-
Type: Investigation
-
Resolution: Fixed
-
Priority: Major - P3
-
Affects Version/s: None
-
Component/s: CLI Module
-
None
-
Not Needed
Problem Description
In the legacy shell, if I run a loop that I need to kill, ctrl+c kills the entire shell. (Not saying this is great behaviour, just as comparison)
joannac@Joannas-MacBook-Pro ~ % mongo --port 32000
MongoDB shell version v4.4.5
...
MongoDB server version: 4.4.5
...
replset:PRIMARY> for(i=0; i<500; i++) { sleep(50)}
^C%
joannac@Joannas-MacBook-Pro ~ %
In mongosh, ctrl+c gets me back the prompt, but the same loop is still running (but there's no indication it is).
joannac@Joannas-MacBook-Pro ~ % mongosh --port 32000 Current Mongosh Log ID: 6081f09bdc7c9f4357d95ee5 Connecting to: mongodb://127.0.0.1:32000/?directConnection=true&serverSelectionTimeoutMS=2000 Using MongoDB: 4.4.5 Using Mongosh Beta: 0.11.0 ... replset [direct: primary]> for(i=0; i<500; i++) { sleep(50)} Error: Asynchronous execution was interrupted by `SIGINT` replset [direct: primary]> printjson(i) 137 replset [direct: primary]> printjson(i) 155
Steps to Reproduce
This is also way more obvious if you actually do something in your loop
replset [direct: primary]> for(i=0;i<1000;i++){printjson(i);sleep(50)}
0
1
2
3
4
5
6
7
8
9
10
11
12
(ctrl-c)
Error: Asynchronous execution was interrupted by `SIGINT`
replset [direct: primary]> 13
14
15
16
17
18
19
20
21
22
23
24
(ctrl-c)
(To exit, press Ctrl+C again or Ctrl+D or type .exit)
replset [direct: primary]> 25
26
27
28
29
30
31
32
33
34
35
36
(ctrl-c)
(I manually inserted (ctrl-c) to show the 3 times I hit ctrl-c
Expected Results
When I hit ctrl-c, in addition to whatever is running at the time (probably the sleep()) getting killed, the actual top level function (the for loop) gets killed.
Or at least, mongosh explains better what it does.
Actual Results
Loops continue to run silently in the background. Which means if I write another loop
for(i=0; i<1000; i++) { //something else}}
That loop starts skipping numbers because there are 2 loops incrementing "i".
Additional Notes
- related to
-
MONGOSH-640 Graceful handling of Ctrl-C
- Closed