Wait until next tick before handling socket errors #1603
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.
Description
Per #1593, there is a currently a race condition where an error in a
socket.write
call can cause the error handler (which clears the command queue) to be fired before the write command is added to the write queue, causing a permanent break in the command queue.While this situation is rare (it occurs once out of 20 tries to reproduce it) it causes significant pain on downstream consumers, which expects node-redis to return the correct responses. Currently, unless the client implements extra verification that the value returned from node-redis is correct, the client can be working with the completely wrong data in their application.
This change adds as little intrusion as possible - wrapping the
on_error
call in aprocess.nextTick()
to ensure the assumption that the code makes about the socket error handling control flow will always be true. (The code currently assumes that the code insideinternalSendCommand
will execute to completion before any error handlers are called.)Checklist
npm test
pass with this change (including linting)?Is a documentation update included (if this change modifies existing APIs, or introduces new ones)?N/A