Uploaded image for project: 'Node.js Driver'
  1. Node.js Driver
  2. NODE-2135

Connection timeout on big query and confusing error message

    • Type: Icon: Bug Bug
    • Resolution: Gone away
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: 3.3.0
    • Component/s: None
    • Labels:
    • Environment:
      Ubuntu Server 16.04

      Mongodb throws MongoNetworkError: connection 0 to mongo:27017 timed out

      const config = require('./config');
      const { MongoClient } = require('mongodb');
      
      const main = async db => {
        const MongoResponses = db.collection('responses');
        const result = await MongoResponses.updateMany(
          { isLocked: { $exists: false } },
          { $set: { isLocked: false } }
        );
        console.log(result);
      }
      
      const run = async () => {
        console.time('connection');
        const connection = new MongoClient(config.db.connection, {
          useUnifiedTopology: true,
          useNewUrlParser: true
        });
      
        await connection.connect();
        const db = connection.db();
        console.timeEnd('connection');
      
        console.time('main');
        try {
          await main(db);
        } catch(error) {
          console.error(error);
        }
        console.timeEnd('main');
      
        connection.close();
      }
      
      run().catch(console.error);
      

      When running the given script, it result in connection timed out after 360018ms 

      connection: 62.376ms
      MongoNetworkError: connection 0 to mongo:27017 timed out
          at Socket.<anonymous> (/apps/limesync/node_modules/mongodb/lib/core/connection/connection.js:335:7)
          at Object.onceWrapper (events.js:291:20)
          at Socket.emit (events.js:203:13)
          at Socket._onTimeout (net.js:434:8)
          at listOnTimeout (internal/timers.js:531:17)
          at processTimers (internal/timers.js:475:7) {
        name: 'MongoNetworkError',
        errorLabels: [ 'TransientTransactionError' ],
        [Symbol(mongoErrorContextSymbol)]: {}
      }
      main: 360018.699ms
      

       

      First issue, the default configuration for connectTimeoutMS is 30000ms.
      The default configuration for socketTimeoutMS us 360000ms.
      So either the driver is using the wrong timeout configuration for this message or the message of the error should be sockert timed out instead of connection timed out or the documented default configuration is wrong.

      Second issue, I don't understand why this query is throwing this error.

      I'm using node-mongodb-native 3.3.0 and MongoDB 4.2.0 with no sharding nor replicas.
      The collection 'responses' has approximately 24.000.000 documents.

       

            Assignee:
            daniel.aprahamian@mongodb.com Daniel Aprahamian (Inactive)
            Reporter:
            tomasgvivo@gmail.com Tomas Gonzalez Vivo
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: