-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Fix async race #1656
Conversation
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 Report
@@ 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
Continue to review full report at Codecov.
|
I've marked this as WIP, because I've discovered a problem with guru. I'll remove the label once it's fixed. |
The problem I was encountering wasn't related to these changes. |
There was a problem hiding this 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
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 withexit_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 simplifygo#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 thatexit_cb
may be called afterclose_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