[SERVER-27560] Ctrl-c in shell password input leaves terminal in non-echo mode Created: 03/Jan/17  Updated: 06/Dec/22  Resolved: 03/Dec/21

Status: Closed
Project: Core Server
Component/s: Shell
Affects Version/s: None
Fix Version/s: None

Type: Bug Priority: Minor - P4
Reporter: Kevin Pulo Assignee: Backlog - Server Tooling and Methods (STM) (Inactive)
Resolution: Won't Fix Votes: 2
Labels: move-stm
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

POSIX


Issue Links:
Duplicate
Related
related to SERVER-764 All tools (including shell) that take... Closed
Assigned Teams:
Server Tooling & Methods
Operating System: ALL
Steps To Reproduce:
  1. Run "mongo -u u -p". There does not need to be a mongod running on the default port.
  2. At the "Enter password:" prompt, type Ctrl-c.
  3. Type a few characters, and observe that they aren't echoed.
  4. Press Enter a few times, and observe the prompt does not appear on a new line.
  5. Type stty echo<enter> or stty sane<enter> to reset the terminal state.

kev@localhost:~$ mongo -u foobar -p
MongoDB shell version v3.4.1
Enter password: 2017-01-03T12:30:50.624+1100 I CONTROL  [main] shutting down with code:0
kev@localhost:~$ kev@localhost:~$ kev@localhost:~$ kev@localhost:~$ kev@localhost:~$ 

kev@localhost:~$ /m/3.2.11/bin/mongo -u foobar -p
MongoDB shell version: 3.2.11
Enter password: kev@localhost:~$ kev@localhost:~$ kev@localhost:~$ kev@localhost:~$ kev@localhost:~$ 

Participants:

 Description   

If the user realises that they have accidentally provided the wrong username when using the shell with plain --password/-p to connect and prompt for the password, a very natural reaction is to hit Ctrl-C to cancel the connection attempt, so that the user can re-run the shell with the correct username.

However, if Ctrl-C is typed while the shell is prompting for a password, the terminal is left in non-echo mode, which messes up the display from that point onwards. The expected behaviour is for the terminal mode to be normal whenever the shell exits, including if it is killed while prompting for a password.

The workaround is the normal one in this situation, ie. the user must (blindly) type stty echo<enter> or stty sane<enter> or reset<enter>.



 Comments   
Comment by Brooke Miller [ 03/Dec/21 ]

We've deprecated the mongo shell in favor of the new mongosh. Unfortunately, we aren't able to pursue improvements to the deprecated shell except in extreme cases, such as critical security fixes. Please start making use of mongosh and let us know if it works for you in this case.

Comment by Joanna Cheng [ 02/Oct/20 ]

Still repros for me with mongo shell 4.0.18, ContOS 7.8.2003

Comment by Kevin Pulo [ 18/May/20 ]

Still repros for me in Ubuntu 18.04, both old versions like 3.4.24, and 4.2.6 and current master. I can imagine that some setups (eg. some *nix shells, or some *nix shell user configs) might forcibly reset the terminal's echo state after running a program, or before printing the shell prompt. Similarly, when I send SIGQUIT (Ctrl-\ on my system) instead of SIGINT (Ctrl-C), the mongo shell throws a backtrace and the terminal is fine afterwards. oleg.pudeyev does one of these situations correspond to your testing?

Comment by Oleg Pudeyev (Inactive) [ 15/May/20 ]

I could not reproduce the issue just now on Debian. Tried 2.6.12 and 3.4.24. Perhaps something changed in the terminal programs or the situation is system-dependent.

Comment by Kevin Pulo [ 13/Jun/19 ]

The passwordPrompt() function introduced in SERVER-24391 exposes the same issue, with a larger opportunity because passwordPrompt() can be called in a loop.

Comment by Joanna Cheng [ 03/Jan/17 ]

Reproduced in OSX 10.11.6 in the native Terminal

Generated at Thu Feb 08 04:15:31 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.