Clear socket.waiting before invoking callbacks #819
Merged
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.
If we
pause()
and then laterresume()
a consumer within a 'done' callback, we can get into a situation where the consumer doesn't actually resume becausesendToBroker
bails out early (becausebroker.socket.waiting
is stilltrue
while the 'done' callback is being invoked, so the fetch request gets thrown away).To work around this I've had to use
setImmediate(() => consumer.resume())
to schedule the resume() to occur after thesocket.waiting
flag has been reset. It works well enough, but it's not very intuitive.This change simply moves the
socket.waiting
reset to occur before we fire off the decoder & associated callbacks. I think this is pretty low risk, but perhaps you can think of a reason why we wouldn't want to do this.Something else to consider: it can be somewhat surprising that requests to brokers are simply "thrown away" if the waiting flag is set: at a minimum, a log message before the
continue
inClient.sendToBroker
would be great (I can add this if you like, it's easy enough).I fFeel like a more "correct" approach would be to fire the callback before that samecontinue
so callers can at least notice that something went screwy, but that seems like a larger change.