[SERVER-2986] Mongo CLI responds poorly to the use of CTRL-C Created: 22/Apr/11  Updated: 30/Apr/19  Resolved: 31/Jul/16

Status: Closed
Project: Core Server
Component/s: Admin, JavaScript, Shell
Affects Version/s: 1.8.1
Fix Version/s: None

Type: Bug Priority: Minor - P4
Reporter: John Schulz Assignee: Unassigned
Resolution: Duplicate Votes: 9
Labels: polish
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Depends
Duplicate
duplicates SERVER-23168 Shell killOperationsOnAllConnections ... Closed
is duplicated by SERVER-4926 segfault in mongo shell Closed
is duplicated by SERVER-7616 Assertion error in mongo shell Closed
is duplicated by SERVER-7835 Shell crashes when canceling a query Closed
Related
related to SERVER-9947 Shell is stuck when primary node stop... Closed
related to SERVER-4460 Improve ctrl-C handling in the shell Closed
Operating System: Linux
Participants:
Case:

 Description   

If a query gets stuck the use of CTRL-C breaks the request but it also breaks the shell session. Each subsequent request to the shell gets the same stack trace response.

> chunk = db.chunks.findOne({"shard":"repset_a"})
 
<CTL-C here>
 
Fri Apr 22 08:31:24 Error: error doing query: unknown shell/collection.js:150
Fri Apr 22 08:31:26 ERROR: MessagingPort::call() wrong id got:715dbf7d expect:715dbf7f
  toSend op: 2004
  response msgid:2801932464
  response len:  36
  response op:  1
  farEnd: 127.0.0.1:7322
Fri Apr 22 08:31:26   Assertion failure false util/message.cpp 512
0x4d4e7e 0x4d7491 0x53ab7e 0x53bd94 0x4ec014 0x4ff2a0 0x4dfc1a 0x4f08e1 0x4eb8bc 0x4efa9c 0x478dcb 0x47b5a3 0x47cde6 0x3e9ee1d994 0x475e99
 ./bin/mongo(_ZN5mongo12sayDbContextEPKc+0xae) [0x4d4e7e]
 ./bin/mongo(_ZN5mongo8assertedEPKcS1_j+0x111) [0x4d7491]
 ./bin/mongo(_ZN5mongo13MessagingPort4recvERKNS_7MessageERS1_+0x32e) [0x53ab7e]
 ./bin/mongo(_ZN5mongo13MessagingPort4callERNS_7MessageES2_+0x34) [0x53bd94]
 ./bin/mongo(_ZN5mongo18DBClientConnection4callERNS_7MessageES2_bPSs+0x34) [0x4ec014]
 ./bin/mongo(_ZN5mongo14DBClientCursor4initEv+0x150) [0x4ff2a0]
 ./bin/mongo(_ZN5mongo12DBClientBase5queryERKSsNS_5QueryEiiPKNS_7BSONObjEii+0x32a) [0x4dfc1a]
 ./bin/mongo(_ZN5mongo18DBClientConnection5queryERKSsNS_5QueryEiiPKNS_7BSONObjEii+0xa1) [0x4f08e1]
 ./bin/mongo(_ZN5mongo17DBClientInterface7findOneERKSsRKNS_5QueryEPKNS_7BSONObjEi+0x7c) [0x4eb8bc]
 ./bin/mongo(_ZN5mongo20DBClientWithCommands10runCommandERKSsRKNS_7BSONObjERS3_i+0x8c) [0x4efa9c]
 ./bin/mongo(_Z21sayReplSetMemberStatev+0x30b) [0x478dcb]
 ./bin/mongo(_Z5_mainiPPc+0x1b53) [0x47b5a3]
 ./bin/mongo(main+0x26) [0x47cde6]
 /lib64/libc.so.6(__libc_start_main+0xf4) [0x3e9ee1d994]
 ./bin/mongo(_ZNSt15basic_streambufIcSt11char_traitsIcEE6xsputnEPKcl+0x51) [0x475e99]
> use config
switched to db config
Fri Apr 22 08:31:36 ERROR: MessagingPort::call() wrong id got:715dbf7f expect:715dbf80
  toSend op: 2004
  response msgid:2801932465
  response len:  114
  response op:  1
  farEnd: 127.0.0.1:7322
Fri Apr 22 08:31:36   Assertion failure false util/message.cpp 512
0x4d4e7e 0x4d7491 0x53ab7e 0x53bd94 0x4ec014 0x4ff2a0 0x4dfc1a 0x4f08e1 0x4eb8bc 0x4efa9c 0x478dcb 0x47b5a3 0x47cde6 0x3e9ee1d994 0x475e99
 ./bin/mongo(_ZN5mongo12sayDbContextEPKc+0xae) [0x4d4e7e]
 ./bin/mongo(_ZN5mongo8assertedEPKcS1_j+0x111) [0x4d7491]
 ./bin/mongo(_ZN5mongo13MessagingPort4recvERKNS_7MessageERS1_+0x32e) [0x53ab7e]
 ./bin/mongo(_ZN5mongo13MessagingPort4callERNS_7MessageES2_+0x34) [0x53bd94]
 ./bin/mongo(_ZN5mongo18DBClientConnection4callERNS_7MessageES2_bPSs+0x34) [0x4ec014]
 ./bin/mongo(_ZN5mongo14DBClientCursor4initEv+0x150) [0x4ff2a0]
 ./bin/mongo(_ZN5mongo12DBClientBase5queryERKSsNS_5QueryEiiPKNS_7BSONObjEii+0x32a) [0x4dfc1a]
 ./bin/mongo(_ZN5mongo18DBClientConnection5queryERKSsNS_5QueryEiiPKNS_7BSONObjEii+0xa1) [0x4f08e1]
 ./bin/mongo(_ZN5mongo17DBClientInterface7findOneERKSsRKNS_5QueryEPKNS_7BSONObjEi+0x7c) [0x4eb8bc]
 ./bin/mongo(_ZN5mongo20DBClientWithCommands10runCommandERKSsRKNS_7BSONObjERS3_i+0x8c) [0x4efa9c]
 ./bin/mongo(_Z21sayReplSetMemberStatev+0x30b) [0x478dcb]
 ./bin/mongo(_Z5_mainiPPc+0x1b53) [0x47b5a3]
 ./bin/mongo(main+0x26) [0x47cde6]
 /lib64/libc.so.6(__libc_start_main+0xf4) [0x3e9ee1d994]
 ./bin/mongo(_ZNSt15basic_streambufIcSt11char_traitsIcEE6xsputnEPKcl+0x51) [0x475e99]
> use config
switched to db config
Fri Apr 22 08:31:39 ERROR: MessagingPort::call() wrong id got:715dbf80 expect:715dbf81
  toSend op: 2004
  response msgid:2801932861
  response len:  114
  response op:  1
  farEnd: 127.0.0.1:7322
Fri Apr 22 08:31:39   Assertion failure false util/message.cpp 512
0x4d4e7e 0x4d7491 0x53ab7e 0x53bd94 0x4ec014 0x4ff2a0 0x4dfc1a 0x4f08e1 0x4eb8bc 0x4efa9c 0x478dcb 0x47b5a3 0x47cde6 0x3e9ee1d994 0x475e99
 ./bin/mongo(_ZN5mongo12sayDbContextEPKc+0xae) [0x4d4e7e]
 ./bin/mongo(_ZN5mongo8assertedEPKcS1_j+0x111) [0x4d7491]
 ./bin/mongo(_ZN5mongo13MessagingPort4recvERKNS_7MessageERS1_+0x32e) [0x53ab7e]
 ./bin/mongo(_ZN5mongo13MessagingPort4callERNS_7MessageES2_+0x34) [0x53bd94]
 ./bin/mongo(_ZN5mongo18DBClientConnection4callERNS_7MessageES2_bPSs+0x34) [0x4ec014]
 ./bin/mongo(_ZN5mongo14DBClientCursor4initEv+0x150) [0x4ff2a0]
 ./bin/mongo(_ZN5mongo12DBClientBase5queryERKSsNS_5QueryEiiPKNS_7BSONObjEii+0x32a) [0x4dfc1a]
 ./bin/mongo(_ZN5mongo18DBClientConnection5queryERKSsNS_5QueryEiiPKNS_7BSONObjEii+0xa1) [0x4f08e1]
 ./bin/mongo(_ZN5mongo17DBClientInterface7findOneERKSsRKNS_5QueryEPKNS_7BSONObjEi+0x7c) [0x4eb8bc]
 ./bin/mongo(_ZN5mongo20DBClientWithCommands10runCommandERKSsRKNS_7BSONObjERS3_i+0x8c) [0x4efa9c]
 ./bin/mongo(_Z21sayReplSetMemberStatev+0x30b) [0x478dcb]
 ./bin/mongo(_Z5_mainiPPc+0x1b53) [0x47b5a3]
 ./bin/mongo(main+0x26) [0x47cde6]
 /lib64/libc.so.6(__libc_start_main+0xf4) [0x3e9ee1d994]
 ./bin/mongo(_ZNSt15basic_streambufIcSt11char_traitsIcEE6xsputnEPKcl+0x51) [0x475e99]
> exit
bye
[root@migsrv-d001 mongodb]# ./bin/mongo --port=7322
MongoDB shell version: 1.8.1
connecting to: 127.0.0.1:7322/test
> use config
switched to db config
> chunk = db.chunks.findOne({"shard":"repset_a"})
> chunk = db.chunks.findOne({"shard":"repset_a"})
{
        "_id" : "MigOidDB.MigOidCol-_id_\"buggzeeann_30324171\"",
        "lastmod" : {
                "t" : 903000,
                "i" : 0
        },
        "ns" : "MigOidDB.MigOidCol",
        "min" : {
                "_id" : "buggzeeann_30324171"
        },
        "max" : {
                "_id" : "bugsylek_25718329"
        },
        "shard" : "repset_a"
}



 Comments   
Comment by Matt [ 30/Apr/19 ]

this doesn't seem like it was ever resolved on macos  (MongoDB shell version v3.6.5)

Comment by William Zola [ 18/Jan/13 ]

This still reproduces in 2.2.2, with a different stack trace.

Fri Jan 18 08:47:21 Assertion: 13111:field not found, expected type 2
0x607e61 0x5d24c9 0x5d264c 0x4b7fa7 0x49f9a7 0x37a32302f0 0x37a3e0dd4f 0x5f9243 0x5f9259 0x5fc844 0x5f596c 0x5f641b 0x5f68d4 0x4f7585 0x520a2d 0x4ea6fa 0x5013e4 0x5bdcbf 0x6ab01c 0x69ca95
mongo(_ZN5mongo15printStackTraceERSo+0x21) [0x607e61]
mongo(_ZN5mongo11msgassertedEiPKc+0x99) [0x5d24c9]
mongo [0x5d264c]
mongo(_ZNK5mongo11shell_utils18ConnectionRegistry30killOperationsOnAllConnectionsEb+0xf17) [0x4b7fa7]
mongo(_Z10quitNicelyi+0x27) [0x49f9a7]
/lib64/libc.so.6 [0x37a32302f0]
/lib64/libpthread.so.0(recv+0x8f) [0x37a3e0dd4f]
mongo(_ZN5mongo6Socket5_recvEPci+0x13) [0x5f9243]
mongo(_ZN5mongo6Socket11unsafe_recvEPci+0x9) [0x5f9259]
mongo(_ZN5mongo6Socket4recvEPci+0xc4) [0x5fc844]
mongo(_ZN5mongo13MessagingPort4recvERNS_7MessageE+0x8c) [0x5f596c]
mongo(ZN5mongo13MessagingPort4recvERKNS_7MessageERS1+0x1b) [0x5f641b]
mongo(ZN5mongo13MessagingPort4callERNS_7MessageES2+0x34) [0x5f68d4]
mongo(_ZN5mongo18DBClientConnection4callERNS_7MessageES2_bPSs+0x55) [0x4f7585]
mongo(_ZN5mongo14DBClientCursor4initEv+0xbd) [0x520a2d]
mongo(_ZN5mongo12DBClientBase5queryERKSsNS_5QueryEiiPKNS_7BSONObjEii+0xea) [0x4ea6fa]
mongo(_ZN5mongo18DBClientConnection5queryERKSsNS_5QueryEiiPKNS_7BSONObjEii+0xa4) [0x5013e4]
mongo(ZN5mongo10mongo_findEP9JSContextP8JSObjectjPlS4+0x32f) [0x5bdcbf]
mongo(js_Invoke+0x40c) [0x6ab01c]
mongo(js_Interpret+0x1305) [0x69ca95]
Fri Jan 18 08:47:22 Error: field not found, expected type 2 src/mongo/shell/collection.js:155
Fri Jan 18 08:47:22 ERROR: MessagingPort::call() wrong id got:2 expect:5
toSend op: 2004
response msgid:8835604
response len: 97
response op: 1
remote: 127.0.0.1:27017
Fri Jan 18 08:47:22 Assertion failure false src/mongo/util/net/message_port.cpp 241

Comment by Tad Marshall [ 16/Apr/12 ]

Some parts are easy (don't exit the shell on ^C while at the prompt) and some are hard (try to stop a server process and handle all responses properly).

Comment by Tad Marshall [ 16/Dec/11 ]

In version 2.1, we are capturing the ctrl-C when we are at the command prompt and can do whatever is appropriate. I will change the behavior to stop using it as an indication that the user wants to exit the shell, you are right, there are other ways to do that.

The other issues mentioned, where a restart of the shell error out with a stack trace, will require some testing to see if I can get it into a state to reproduce the bad behavior.

Comment by John Schulz [ 24/Apr/11 ]

see http://www.faqs.org/docs/bashman/bashref_51.html#SEC51 or http://dev.mysql.com/doc/refman/5.5/en/mysql.html for examples of reasonable behavior for a shell's response to the receipt of ctrl-c. Terminating the current command with a stack trace and then refusing to do anything but display a stack trace on subsequent requests is not reasonable and can be outright confusing.

Comment by Eliot Horowitz (Inactive) [ 23/Apr/11 ]

agree it should be better, but not exactly sure what "correct" is

Comment by Neil Hooey [ 22/Apr/11 ]

I believe the shell should do the same thing that bash does when you hit CTRL+C, clear whatever text has been typed at the prompt, print a new prompt line, and most importantly, NOT exit.

Here are some reasons I think are important:
1. If you hit CTRL+C more than once to kill a query, you get booted out of the shell
2. We already have CTRL+D for exiting, and mongo actually says "bye" when you do this
3. It's the easiest way to cancel what you've already typed
4. It's consistent with bash, which has a lot of sway in user behaviour

MySQL has the same problem, and it's really annoying.

Generated at Thu Feb 08 03:01:45 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.