Repository navigation
Debounce message events - #1087
Merged
Merged
Conversation
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The following pattern has a race condition described in #1070:
That's because the subprocess might respond between those two calls, in which case
subprocess.getOneMessage()hangs forever. In #1077, we introduced asubprocess.exchangeMessage()to fix this problem.However, to avoid race conditions, users must remember to use that method. Also, there is a series of "Best practices" that we documented: in essence, there are many pitfalls to avoid to make sure IPC does not run into similar race conditions as above.
This PR implements a better solution to the underlying problem: it debounces IPC messages. Unlike the current solution, this does not require users to remember any pattern or best practice: it works automatically. This removes any race condition not only from the example above, but also from the following additional situations.
This also removes the need for the
exchangeMessage()method, which simplifies the API. It was a little confusing whether this method sent then received a message, or received then sent a message. Since sending and receiving messages are now separate methods, this is much clearer.This PR also adds lots of tests to cover several edge cases.
Finally, this implementation works better when mixing both Execa's IPC methods and the native Node.js IPC methods. Previously, mixing the two could lead to some issues.