-
Type:
Bug
-
Resolution: Unresolved
-
Priority:
Trivial - P5
-
None
-
Affects Version/s: None
-
Component/s: Shell
-
None
-
Server Tooling & Methods
-
ALL
-
-
(copied to CRM)
-
None
-
0
-
None
-
None
-
None
-
None
-
None
-
None
Hi,
If I understand the following source code snippet correctly, the mongo shell will not write the history file if the process is non-interactive but ::shellHistoryDone() is registered as a shutdown task at the very beginning of _main.
// mongo/src/mongo/shell/dbshell.cpp int _main(int argc, char* argv[], char** envp) { registerShutdownTask([] { ... ::killOps(); ::shellHistoryDone(); }); ... if (shellGlobalParams.files.size() == 0 && shellGlobalParams.script.empty()) shellGlobalParams.runShell = true; ... if (shellGlobalParams.runShell) { ... shellHistoryInit(); while (1) {...} shellHistoryDone(); } ... }
As a result: if a non-interactive mongo shell aborts, it will try to save history and report error [main] Error saving history file: FileOpenFailed: Unable to open() file : No such file or directory because the history file name is empty.
I understand that mongo shell will continue working and this error message can actually serve as an indication that the non-interactive mongo shell aborts. However, I found some were confused by the error. Therefore, I'd suggest either move registering ::shellHistoryDone() as a shutdown task into the interactive loop if (shellGlobalParams.runShell) or skip linenoiseHistorySave in shellHistoryDone() if the history file path is empty.
Regards,
Lungang