zodern / meteor-up

Production Quality Meteor Deployment to Anywhere
http://meteor-up.com/
MIT License
1.28k stars 279 forks source link

Every deploy suddenly failing with MongoServerSelectionError: connect ECONNREFUSED 127.0.0.1:27017 #1303

Closed renanlecaro closed 2 years ago

renanlecaro commented 2 years ago

Hi

I've been deploying with mup without problem for about 2 years. Today the deploy failed, the node app couldn't connect to the local mongo server. It seems to be related to the node version (14.x.x) that got auto chosen by the node-version script (/home/app/scripts/node-version.js ) in the docker image "zodern/meteor".

I'm posting this to help other people with the same problem.

The fix was to force an older version with this bit of env config

      "EXACT_NODE_VERSION": "\"v12.14.0\"",

then restart the app with mup reconfig

I'm not sure how specific that problem is to my config and deploy setup (digital ocean) but it really took me by surprise, so I'm posting it here. I affected all my deploys at once, in production and on my separate staging server.

Mup version (mup --version): 1.5.7

Mup config

{
  "servers": {
    "one": {
      "host": "1.2.3.4",
      "username": "root",
      "pem": "~/.ssh/pem"
    }
  },
  "app": {
    "name": "my-app",
    "path": "../",
    "servers": {
      "one": {}
    },
    "deployCheckWaitTime": 300,
    "buildOptions": {
      "serverOnly": true,
      "buildLocation": "/tmp/mup-meteor-cxxxxxxxxxxxxxxxxxxxxxxx",
      "cleanBuildLocation": true
    },
    "env": {
      "ROOT_URL": "https://subdomain.host.com",
      "MONGO_URL": "mongodb://mongodb:27017/my-app",
      "MONGO_OPLOG_URL": "mongodb://mongodb/local",
      "ENV": "PRODUCTION", 
      "EXACT_NODE_VERSION": "\"v12.14.0\"",
      "TZ": "Europe/Paris"
    },
    "docker": {
      "image": "zodern/meteor",
      "stopAppDuringPrepareBundle": true,
      "imagePort": 3000,
      "args": [
        "--link=mongodb:mongodb"
      ]
    },
    "enableUploadProgressBar": true,
    "type": "meteor"
  },
  "mongo": {
    "version": "4.4.4",
    "servers": {
      "one": {}
    },
    "dbName": "ciboulette"
  }
}

Final output of mup deploy command after checking for a very long time :

MongoServerSelectionError: connect ECONNREFUSED 127.0.0.1:27017
        at Timeout._onTimeout (/built_app/programs/server/npm/node_modules/meteor/npm-mongo/node_modules/mongodb/lib/core/sdam/topology.js:437:30)
        at listOnTimeout (internal/timers.js:557:17)
        at processTimers (internal/timers.js:500:7) {
      reason: TopologyDescription {
        type: 'ReplicaSetNoPrimary',
        setName: 'meteor',
        maxSetVersion: 1,
        maxElectionId: ObjectID {
          _bsontype: 'ObjectID',
          id: Buffer(12) [Uint8Array] [
            127, 255, 255, 255, 0,
              0,   0,   0,   0, 0,
              0,   5
          ]
        },
        servers: Map(1) {
          '127.0.0.1:27017' => ServerDescription {
            address: '127.0.0.1:27017',
            error: Error: connect ECONNREFUSED 127.0.0.1:27017
                at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1159:16) {
              name: 'MongoNetworkError'
            },
            roundTripTime: -1,
            lastUpdateTime: 19317600378,
            lastWriteDate: null,
            opTime: null,
            type: 'Unknown',
            topologyVersion: undefined,
            minWireVersion: 0,
            maxWireVersion: 0,
            hosts: [],
            passives: [],
            arbiters: [],
            tags: []
          }
        },
        stale: false,
        compatible: true,
        compatibilityError: null,
        logicalSessionTimeoutMinutes: null,
        heartbeatFrequencyMS: 10000,
        localThresholdMS: 15,
        commonWireVersion: 9
      }
    }
    => Setting node version
    NODE_VERSION=14.18.1
    v14.18.1 is already installed.
    Now using node v14.18.1 (npm v6.14.15)
    default -> 14.18.1 (-> v14.18.1 *)
    => Starting meteor app on port 3000
renanlecaro commented 2 years ago

My change did let the app restart, but trying to deploy anything with "mup deploy" quickly throws this

 failed to process "\"\\\"v12.14.0\"\"": unexpected end of statement while looking for matching double-quote

I'll check back tomorrow, the app is running now so i'll stop touching it. My latest changes i originally wanted to deploy are still not out

renanlecaro commented 2 years ago

Just realized EXACT_NODE_VERSION is a boolean flag. Still trying to get my apps to deploy

renanlecaro commented 2 years ago

I tried forcing the version by adding this in the env part of the mup.js file

EXACT_NODE_VERSION: true,
NODE_VERSION: "v12.14.0",

but then mup deploy crashed with this error

]=> Setting node version
[188.166.160.106]NODE_VERSION=v12.14.0
[188.166.160.106]v12.14.0 is already installed.
[188.166.160.106]Now using node v12.14.0 (npm v6.13.4)
[188.166.160.106]default -> v12.14.0 *
[188.166.160.106]=> Starting meteor app on port 3000
[188.166.160.106]## There is an issue with `node-fibers` ##
[188.166.160.106]`/built_app/programs/server/node_modules/fibers/bin/linux-x64-72-glibc/fibers.node` is missing.
[188.166.160.106]
[188.166.160.106]Try running this to fix the issue: /home/app/.nvm/versions/node/v12.14.0/bin/node /built_app/programs/server/node_modules/fibers/build
[188.166.160.106]Error: Cannot find module '/built_app/programs/server/node_modules/fibers/bin/linux-x64-72-glibc/fibers'
[188.166.160.106]Require stack:
[188.166.160.106]- /built_app/programs/server/node_modules/fibers/fibers.js
[188.166.160.106]- /built_app/programs/server/boot.js
[188.166.160.106]- /built_app/main.js
[188.166.160.106]    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:797:15)
[188.166.160.106]    at Function.Module._load (internal/modules/cjs/loader.js:690:27)
[188.166.160.106]    at Module.require (internal/modules/cjs/loader.js:852:19)
[188.166.160.106]    at require (internal/modules/cjs/helpers.js:74:18)
[188.166.160.106]    at Object.<anonymous> (/built_app/programs/server/node_modules/fibers/fibers.js:14:39)
[188.166.160.106]    at Module._compile (internal/modules/cjs/loader.js:959:30)
[188.166.160.106]    at Module.Mp._compile (/built_app/programs/server/runtime.js:99:23)
[188.166.160.106]    at Object.Module._extensions..js (internal/modules/cjs/loader.js:995:10)
[188.166.160.106]    at Module.load (internal/modules/cjs/loader.js:815:32)
[188.166.160.106]    at Module.Mp.load (/built_app/programs/server/runtime.js:46:33)
[188.166.160.106]/built_app/programs/server/node_modules/fibers/fibers.js:23
[188.166.160.106]       throw new Error('Missing binary. See message above.');
[188.166.160.106]       ^
[188.166.160.106]
[188.166.160.106]Error: Missing binary. See message above.
[188.166.160.106]    at Object.<anonymous> (/built_app/programs/server/node_modules/fibers/fibers.js:23:9)
[188.166.160.106]    at Module._compile (internal/modules/cjs/loader.js:959:30)
[188.166.160.106]    at Module.Mp._compile (/built_app/programs/server/runtime.js:99:23)
[188.166.160.106]    at Object.Module._extensions..js (internal/modules/cjs/loader.js:995:10)
[188.166.160.106]    at Module.load (internal/modules/cjs/loader.js:815:32)
[188.166.160.106]    at Module.Mp.load (/built_app/programs/server/runtime.js:46:33)
[188.166.160.106]    at Function.Module._load (internal/modules/cjs/loader.js:727:14)
[188.166.160.106]    at Module.require (internal/modules/cjs/loader.js:852:19)
[188.166.160.106]    at require (internal/modules/cjs/helpers.js:74:18)
[188.166.160.106]    at Object.<anonymous> (/built_app/programs/server/boot.js:2:15)

Looks like the build is made with the specified version, but the npm install is maybe done with another one, and then the compiled dependencies are not for the right version ? Not sure.

I though that maybe it was simply a problem of upgrading my meteor version, so i upgraded my app to 2.6, then deployed without forcing a version. I got the same problem of the mongo node lib not managing to connect to the local mongo server. But now my app requires node 14, i got the following error when trying to build it on node 12 :

=> Starting meteor app on port 3000
    Meteor requires Node v14.0.0 or later.
    => Setting node version
    NODE_VERSION=v12.14.0
    v12.14.0 is already installed.
    Now using node v12.14.0 (npm v6.13.4)
    default -> v12.14.0 *
    => Starting meteor app on port 3000
    Meteor requires Node v14.0.0 or later.
renanlecaro commented 2 years ago

Upgrading mup and meteor to the latest version, runningmup setup (what i was missing) then mup deploy worked.

ddaydd commented 2 years ago

great, you can surely close this issue .