Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix async race #1656

Merged
merged 7 commits into from
Jan 28, 2018
Merged

Fix async race #1656

merged 7 commits into from
Jan 28, 2018

Conversation

bhcleek
Copy link
Collaborator

@bhcleek bhcleek commented Jan 22, 2018

Eliminate race conditions that were possible in vim8 job handling.

Most jobs were only handling the exit_cb handler for job options. To make sure that all messages are handled, close_cb has to be hooked up and coordinated with exit_cb, because there is no guarantee about which order they will be called in.

Refactor autoload/go/job.vim to call the caller-provided callbacks only after the job has exited and channel has been closed so that the actual exit status and all messages can be provided. I also took this opportunity to clean up and simplify go#job#Spawn so that there's only one callback called when the job completes instead of two and so that the return value only exposes the callbacks that are needed by the caller.

Refactor autoload/go/guru.vim to account for the fact that it's possible that exit_cb may be called after close_cb.

Refactor all other async jobs to coordinate calling functions that should be called only after the job's exit status is known and all the channel is closed.

Because this touched so much code, I tried to make each of the commits focused on a single area of improvement. You may find it much easier to review each commit rather than reviewing them all at once.

Closes #1440

There may still be data data in the channel when the job exits.
Conversely, the exit callback may be called after the channel is closed.
To handle both situations, only call callbacks with exit status and all
the messages once the job has exited and the channel has been closed.

Replace the error_info_cb and custom_cb keys with a single new key,
complete.
Only return the necessary callbacks from go#job#Spawn. Data that's
needed during the execution of the callbacks is wrapped in a closure
instead.

Do not allow the caller to provide an exit_cb or close_cb; there are no
current use cases that do so, and further changes would need to be made
to ensure that the complete handler would be called if only one of
exit_cb or close_cb were called.
@codecov-io
Copy link

codecov-io commented Jan 22, 2018

Codecov Report

Merging #1656 into master will increase coverage by 0.31%.
The diff coverage is 27.43%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1656      +/-   ##
==========================================
+ Coverage   21.73%   22.05%   +0.31%     
==========================================
  Files          53       53              
  Lines        4173     4217      +44     
==========================================
+ Hits          907      930      +23     
- Misses       3266     3287      +21
Flag Coverage Δ
#nvim 16.71% <0%> (-0.18%) ⬇️
#vim74 19.18% <0%> (-0.21%) ⬇️
#vim80 20.91% <27.43%> (+0.3%) ⬆️
Impacted Files Coverage Δ
autoload/go/def.vim 21.54% <ø> (+0.23%) ⬆️
autoload/go/coverage.vim 0% <0%> (ø) ⬆️
autoload/go/rename.vim 0% <0%> (ø) ⬆️
autoload/go/job.vim 0% <0%> (ø) ⬆️
autoload/go/cmd.vim 5.73% <0%> (ø) ⬆️
autoload/go/guru.vim 9.65% <0%> (-0.31%) ⬇️
autoload/go/test.vim 72.31% <75%> (+1.65%) ⬆️
autoload/go/lint.vim 55.42% <86.36%> (+8.53%) ⬆️
autoload/go/list.vim 65.33% <0%> (-1.34%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update ffb2f43...aef5e20. Read the comment docs.

@bhcleek bhcleek added the wip label Jan 24, 2018
@bhcleek
Copy link
Collaborator Author

bhcleek commented Jan 24, 2018

I've marked this as WIP, because I've discovered a problem with guru. I'll remove the label once it's fixed.

@bhcleek bhcleek removed the wip label Jan 25, 2018
@bhcleek
Copy link
Collaborator Author

bhcleek commented Jan 25, 2018

The problem I was encountering wasn't related to these changes.

Copy link
Contributor

@arp242 arp242 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems okay in a quick review/test

@bhcleek bhcleek merged commit 18b9897 into fatih:master Jan 28, 2018
@bhcleek bhcleek deleted the fix-async-race branch January 28, 2018 15:37
bhcleek added a commit that referenced this pull request Jan 29, 2018
Update CHANGELOG.md for #1652, #1653, #1656, and #1664.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Check for race conditions similar to the one fixed in #1439
3 participants