Uploaded image for project: 'MongoDB Shell'
  1. MongoDB Shell
  2. MONGOSH-707

Ctrl+C doesn't actually kill running loop in mongosh

    • Type: Icon: Investigation Investigation
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 0.13.1
    • 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

            Assignee:
            michael.rose@mongodb.com Michael Rose (Inactive)
            Reporter:
            joanna.cheng@mongodb.com Joanna Cheng
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: