fix(cli-repl): do not recursively push() in LineByLineInput MONGOSH-586 #659
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.
First half of addressing MONGOSH-586.
Before this commit, what could happen in blocked mode is that:
released
to another
_flush()
call_flush()
call would start emitting data whilewe were already doing so, which is not something that the
readline implementation expects from its input stream
(which is arguably a bug in Node.js)
Concretely, in the situation described in the ticket:
.editor
puts the stream into blockingmode (the other half of the ticket)
is forwarded immediately
'SIGINT' event
.displayPrompt()
when thatevent is received
.displayPrompt()
handler explicitly callsnextLine()
nextLine()
leads to another_flush()
call, which would thenstart emitting queued up data while the
.push()
call for theCtrl+C
is still on the stackbecause generators can’t have their
.next()
function calledrecursively
In order to fix this, we do not process
._flush()
calls whenwe are already inside a
.push()
call. This should be a reasonablefix, because the situations in which we call
.push()
are:_flush()
itself, where it’s okay to skip_flush()
calls because the input character queue is being processed already
_forwardAndBlockOnNewline()
for urgent events(Ctrl+C/Ctrl+D), where it’s also okay to skip
_flush()
callsbecause we call that immediately afterwards
_forwardWithoutBlocking()
, where the assumption would bethat there is no character queue to be flushed in the first place
Unfortunately, this adds a bit of extra complexity to the already
somewhat complicated
LineByLineInput
implementation.