-
Notifications
You must be signed in to change notification settings - Fork 31.3k
After calling setupHistory, the program continues to run even after the REPL is closed. #52386
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
Comments
Hi @LiST-GIT, according to the document, the rl.close() method closes the Interface instance and relinquishes control over the input and output streams. When called, the 'close' event will be emitted. Calling rl.close() does not immediately stop other events (including 'line') from being emitted by the Interface instance. IMO, rl.close() does not exit the process. In the test code, I wrote 2 samples to make the test code work smoothly:
It quits the node process very soon without giving users chance to input and save into history.
|
If agreed, would I submit a PR to explain the repl.close() behavior more clearly especially for stdin and stdou cases instead of file stream cases? |
Thank you for your response @lucshi . I've updated the code again. In the callback of setupHistory, calling r.pause can now properly exit the program. I think it might be because r.close already calls r.pause, but in setupHistory, due to the asynchronous fd executing the open callback, r.resume is called again, which is why it continues to wait on stdin. Is this by design? const repl = require('repl');
var r = repl.start({});
r.setupHistory(__dirname + '/history', () => {
r.pause();
});
r.close(); |
According to the REPL implementation , setupHistory resumes the REPL again even if it has been closed. IMHO, in real pracise, users (programmers) ought to know the callback of setupHistory occurs after r.close() so the original code snippet does not make great sense although it is a great corner test case. Usually users are supposed to do some evaluations to well use REPL after history setup. A common code snippet found on web be like :
As the REPL API manuals does not give such a clear sample to demostrate how to close the REPL gracefully. I think complementing the document could be a quick solution. What's your advice here? |
I think you're right, the programmer should determine the order of setupHistory and close themselves. |
Emphasize "setupHistory" could avoid repl from closing and users shall take care of repl closing in appropriate methods. Fixes: nodejs#52386
I think I can submit a PR to resolve this issue even if the close is done ahead of setupHistory. |
Version
v20.5.0
Platform
macos
Subsystem
No response
What steps will reproduce the bug?
How often does it reproduce? Is there a required condition?
No response
What is the expected behavior? Why is that the expected behavior?
No response
What do you see instead?
After calling setupHistory, the program continues to run even after the REPL is closed.
Additional information
No response
The text was updated successfully, but these errors were encountered: