mongo icon indicating copy to clipboard operation
mongo copied to clipboard

SERVER-46007 ignore SIGINT when input password in stdin

Open lifubang opened this issue 4 years ago • 0 comments

Problem:

mongo causes os shell crash if we type ctrl + c when entering password in stdin.

In linux platform:

When we login to mongo server in shell with -p args but don't pass the password in the argument list, then mongo shell will prompt us Enter password: to enter the password from stdin. At that time, if we send ctrl +c(SIGINT) to stdin, the mongo shell will be closed, but at the same time, user's os shell will be crashed, and we can't input anything in the shell. We must close the whole shell session and login again to do other maintaining job.

In windows platform, there is no such problem.

I think we should ignore ctrl c when we type password in stdin, just like other database client shell, such as mysql.

Step to reproduce:

login a new linux shell, and use mongo shell:

root@DESKTOP-UVUP1SF:/opt/mongo# build/opt/mongo/mongo localhost:14821/admin -u node -p

Press enter key, then it will prompt us to enter password without echo in the screen:

root@DESKTOP-UVUP1SF:/opt/mongo# build/opt/mongo/mongo localhost:14821/admin -u node -p
Enter password:

At that time, we input some password, but don't press enter key. Instead of it, we type ctrl c:

root@DESKTOP-UVUP1SF:/opt/mongo# build/opt/mongo/mongo localhost:14821/admin -u node -p
Enter password: 2020-02-06T12:14:21.173+0800 I CONTROL [main] shutting down with code:0
root@DESKTOP-UVUP1SF:/opt/mongo#

Because of SIGINT, the mongo shell closed normally, and returned to user's os main shell.

But in user's os main shell, we can't input anything more.

root@DESKTOP-UVUP1SF:/opt/mongo# build/opt/mongo/mongo localhost:14821/admin -u node -p
Enter password: 2020-02-06T12:14:21.173+0800 I CONTROL [main] shutting down with code:0
root@DESKTOP-UVUP1SF:/opt/mongo# root@DESKTOP-UVUP1SF:/opt/mongo# root@DESKTOP-UVUP1SF:

User's os main shell is crash now.

Signed-off-by: lifubang [email protected]

lifubang avatar Feb 06 '20 07:02 lifubang