[SERVER-46028] non-interactive mongo shell tries to write history file before aborting Created: 07/Feb/20 Updated: 06/Dec/22 |
|
| Status: | Backlog |
| Project: | Core Server |
| Component/s: | Shell |
| Affects Version/s: | None |
| Fix Version/s: | None |
| Type: | Bug | Priority: | Trivial - P5 |
| Reporter: | Lungang Fang | Assignee: | Backlog - Server Tooling and Methods (STM) (Inactive) |
| Resolution: | Unresolved | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Assigned Teams: |
Server Tooling & Methods
|
|||
| Operating System: | ALL | |||
| Steps To Reproduce: |
|
|||
| Participants: | ||||
| Case: | (copied to CRM) |
| Description |
|
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.
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, |
| Comments |
| Comment by Steven Vannelli [ 10/May/22 ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Moving this ticket to the Backlog and removing the "Backlog" fixVersion as per our latest policy for using fixVersions. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Kevin Pulo [ 10/Feb/20 ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Excellent clarification, thanks! | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Lungang Fang [ 10/Feb/20 ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Hi Kev, Thanks for looking into this issue. Firstly, my apologies for the confusion. The behaviour I reported was for 4.0.14 but the source code I referred to is 4.2.
There are related but not exactly the same. The issue reported here is: when a mongo shell decides to abort, it tries to write the history file even if it is a non-interactive session. As a result, in 4.0, it will hit
In 4.2, I can confirm that the issue still exists but the symptom is different because of changes introduced in commit 159eba44d7a. In branch 4.0, the history file path is initialized in shellHistoryInit(), which is only called for interactive sessions (see below). Therefore, non-interactive mongo shell sessions will get empty history file path and hence report the error I reported earlier.
In comparison, after the commit 159eba44d7a, the history file path is constructed from the user's home dir on the fly:
As a result, if a non-interactive mongo shell session aborts, it will able to get the history file path and update the history file. However, in my opinion, non-interactive mongo shell sessions should not update the history file in any circumstances. Even worse, according to my tests with 4.2 (see below), a non-interactive mongo shell session will truncated the history file should it abort. I believe this is because shellHistoryInit() is not called for non-interactive sessions.
Running the tests again with the file permission of the history file changed to read only (see below), we can see clearly that:
In summary, both 4.0 and 4.2 non-interactive mongo shell sessions try to write the shell history file, which is not desired and causes different issues in different branches. Since it is common to not record commands in non-interactive sessions, I believe the best (and least surprising) fix for this issue is to not register shellHistoryDone() as a shutdown task for non-interactive mongo shell sessions. Best Regards, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Kevin Pulo [ 07/Feb/20 ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Is this a duplicate of |