Port issues when running multiple unrelated apps locally

I recently updated my app to version 1.2 (currently 1.2.0.2). I got things to a point where they seemed to be working for the most part, but after issuing

meteor reset 

things went south. My data initialization code indicated that a bunch of users already existed. Then I noticed that my app was apparently not using port 3000 like it always had and meteor was not starting mongo:

=> Started proxy.
=> Started your app.

=> App running at: http://localhost:5000/

I recognized port 5000 as the port used by a separate meteor app (voicecode.io, an unrelated product that I purchased).

I don’t think that port 5000 was actually being used by my app since I could still access the app at port 3000 and the other app still works at port 5000, but my app did seem to use port 5001 for mongo, which is disturbing. I want my app to just use ports 3000 and 3001, so I tried setting the port when starting meteor, but it still seems to behave the same way. If I close the other app (voicecode) and run my app then it cannot find mongo since it is looking at port 5001:

> /usr/local/bin/meteor --settings settings.test.json --port 3000
> [[[[[ ~/easy-bid ]]]]]

> => Started proxy.
> W20151004-12:12:12.466(-4)? (STDERR) 
> W20151004-12:12:12.467(-4)? (STDERR) /Users/markphillips/.meteor/packages/meteor-tool/.1.1.9.1aa9gcm++os.osx.x86_64+web.browser+web.cordova/mt-os.osx.x86_64/dev_bundle/server-lib/node_modules/fibers/future.js:278
> W20151004-12:12:12.468(-4)? (STDERR) 						throw(ex);
> W20151004-12:12:12.468(-4)? (STDERR) 						      ^
> W20151004-12:12:12.468(-4)? (STDERR) Error: failed to connect to [127.0.0.1:5001]
> W20151004-12:12:12.468(-4)? (STDERR)     at Object.Future.wait (/Users/markphillips/.meteor/packages/meteor-tool/.1.1.9.1aa9gcm++os.osx.x86_64+web.browser+web.cordova/mt-os.osx.x86_64/dev_bundle/server-lib/node_modules/fibers/future.js:398:15)
> W20151004-12:12:12.468(-4)? (STDERR)     at new MongoConnection (packages/mongo/mongo_driver.js:213:1)
> W20151004-12:12:12.468(-4)? (STDERR)     at new MongoInternals.RemoteCollectionDriver (packages/mongo/remote_collection_driver.js:4:1)
> W20151004-12:12:12.468(-4)? (STDERR)     at Object.<anonymous> (packages/mongo/remote_collection_driver.js:38:1)
> W20151004-12:12:12.468(-4)? (STDERR)     at Object.defaultRemoteCollectionDriver (packages/underscore/underscore.js:750:1)
> W20151004-12:12:12.468(-4)? (STDERR)     at new Mongo.Collection (packages/mongo/collection.js:98:1)
> W20151004-12:12:12.468(-4)? (STDERR)     at AccountsServer.AccountsCommon (accounts_common.js:23:18)
> W20151004-12:12:12.468(-4)? (STDERR)     at new AccountsServer (accounts_server.js:16:5)
> W20151004-12:12:12.468(-4)? (STDERR)     at Package (globals_server.js:5:12)
> W20151004-12:12:12.469(-4)? (STDERR)     at /Users/markphillips/easy-bid/.meteor/local/build/programs/server/packages/accounts-base.js:1813:4
> W20151004-12:12:12.469(-4)? (STDERR)     - - - - -
> W20151004-12:12:12.469(-4)? (STDERR)     at [object Object].<anonymous> (/Users/markphillips/.meteor/packages/npm-mongo/.1.4.39_1.15lx5z++os+web.browser+web.cordova/npm/node_modules/mongodb/lib/mongodb/connection/server.js:556:74)
> W20151004-12:12:12.469(-4)? (STDERR)     at [object Object].emit (events.js:106:17)
> W20151004-12:12:12.469(-4)? (STDERR)     at [object Object].<anonymous> (/Users/markphillips/.meteor/packages/npm-mongo/.1.4.39_1.15lx5z++os+web.browser+web.cordova/npm/node_modules/mongodb/lib/mongodb/connection/connection_pool.js:156:15)
> W20151004-12:12:12.469(-4)? (STDERR)     at [object Object].emit (events.js:98:17)
> W20151004-12:12:12.469(-4)? (STDERR)     at Socket.<anonymous> (/Users/markphillips/.meteor/packages/npm-mongo/.1.4.39_1.15lx5z++os+web.browser+web.cordova/npm/node_modules/mongodb/lib/mongodb/connection/connection.js:534:10)
> W20151004-12:12:12.469(-4)? (STDERR)     at Socket.emit (events.js:95:17)
> W20151004-12:12:12.469(-4)? (STDERR)     at net.js:441:14
> W20151004-12:12:12.469(-4)? (STDERR)     at process._tickCallback (node.js:448:13)
> => Exited with code: 8

I need meteor to spin up a mongo instance using port 3001 for my app. This all used to just happen, but now it doesn’t and I don’t know how to get things back to normal. This is related to https://github.com/meteor/meteor/issues/4986, but I think this is a little different since I’m just trying to use the default ports.

Meteor always starts a new instance of mongodb which listens on PORT+1 therefore if you run two apps with

meteor --port 3000
meteor --port 5000

you will end up with two separate/unrelated mongodb instances that listen on 3001 and 5001 respectively.

If you wish to run only a single instance you can either use a dedicated mongodb instance or point the second app to the first one’s DB using MONGO_URL environment variable.

Thanks for the reply. But meteor is not starting a new instance of mongodb in my case and is not using [the port I specified] + 1. My questions could be reworded “why has meteor stopped its prior behavior of starting a new instance of mongodb” and “why is it looking for mongo on port 5001 when I passed in ‘-- port 3000’?”

Oh, my bad. i was not aware of such change of behavior.

I also wonder why you would not opt for a dedicated mongodb instance,
though.

I discovered that my problem had to do with running my app from within WebStorm. Somehow it got mixed up and applied a bunch of environment settings for a different app when running my app. So even though the app was launched with

meteor --settings settings.test.json --port 3000

It had several incorrect environment variable settings such as these:

MONGO_URL=mongodb://127.0.0.1:5001
ROOT_URL=http://localhost:5000

Running the app from terminal works fine. I was able to see all of the environment settings for the relevant node process by using this command where {PID} is the process id:

ps eww {PID}

WebStorm lets you set environment variables, but I had no environment variables set.

1 Like