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

mongosh exits while running a script if primary node goes down

    • Type: Icon: Bug Bug
    • Resolution: Unresolved
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: 2.3.1
    • Component/s: None
    • Environment:
    • Developer Tools

      Problem Statement/Rationale

      What is going wrong? What action would you like the Engineering team to take?

      MongoDB nodes A,B,C configured as 3-node replica set. Node A has higher priority.
      mongosh connects to the RS, runs a script containing an infinite loop
      User kills mongod process on Node A (kill -9 <pid>)
      mongosh process exits

      Expected: mongosh does not exit; driver retries the write

      Please be sure to attach relevant logs with any sensitive data redacted.
      How to retrieve logs for: Compass; Shell

      {"t":

      {"$date":"2024-09-26T15:55:42.028Z"}

      ,"s":"E","c":"MONGOSH","id":1000000006,"ctx":"startup","msg":"Error: read ECONNRESET","attr":{"stack":"Error: read ECONNRESET\n at TCP.onStreamRead (node:internal/stream_base_commons:218:20)","name":"Error","message":"read E
      CONNRESET","code":"ECONNRESET","errno":-104,"syscall":"read"}}

      Steps to Reproduce

      How could an engineer replicate the issue you’re reporting?

      1. Create 3-node RS
      2. Create JS script to perform insertOne() in an infinite loop
      3. Create JS script to perform find(); cursor.next() in an infinite loop
      4. Run each script in a separate mongosh shell - use either mongosh "mongodb://mongoadmin:passwordone@mongodb-emea,mongodb-us,mongodb-apac/?replicaSet=TestRS" script.js OR load("script.js")
      5. Kill the primary server using kill -9 <pid>
      6. Observe the mongosh instances exit.

      Expected Results

      What do you expect to happen?
      The mongosh instances should NOT exit

      Actual Results

      What do you observe is happening?
      The mongosh instances exit with Error: read ECONNRESET

      Additional Notes

      Any additional information that may be useful to include.

      We have an environment set up where you can test this - we discovered the problem while testing an Instructor-Led Training module on the new Instruqt lab environment. Please contact me via Slack to arrange access.

      Scripts we use:

      record =  {  name: "A. Customer",  address : "1600 Hoover Avenue",  type: "Loan Application",value: 50000}
      db.loans.drop()while(true) {  var v = db.loans.insertOne(record,{writeConcern: { w: "majority" }}) print ("Recorded application " + v.insertedId)}
      lastidseen=MinKey
      while(true) {   var cursor = db.loans.find({_id:{$gt:lastidseen}})   while (cursor.hasNext()) {
         var v = cursor.next()  var id = v._id  print("Sending a mail to A.Customer about application " +id)  lastidseen = id; }
      } 

        1. Untitled document.pdf
          37 kB
          Peter Hubbard

            Assignee:
            Unassigned Unassigned
            Reporter:
            peter.hubbard@mongodb.com Peter Hubbard
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated: