Cannot connect to Mongo Server

There are no mongo server or any servers or any services running on that ip:port but we are still getting this kind of error.

(lockerdb) Database connection error: { [Error: failed to connect to [127.0.0.1:10004]]
  [stack]: [Getter/Setter],
  [message]: 'failed to connect to [127.0.0.1:10004]',
  [arguments]: undefined,
  [type]: undefined }


node.js:201

        throw e; // process.nextTick error, or 'error' event on first tick






        ^

TypeError: Cannot call method 'close' of null
    at /home/<user>/Documents/Server_v1/ssc/ssc-lac/lac-util.js:1653:15
    at /home/<user>/node_modules/mongodb/lib/mongodb/db.js:247:16
    at [object Object].<anonymous> (/home/<user>/node_modules/mongodb/lib/mongodb/connection/server.js:383:7)
    at [object Object].emit (events.js:88:20)
    at [object Object].<anonymous> (/home/<user>/node_modules/mongodb/lib/mongodb/connection/connection_pool.js:93:15)
    at [object Object].emit (events.js:70:17)
    at Socket.<anonymous> (/home/<user>/node_modules/mongodb/lib/mongodb/connection/connection.js:385:10)
    at Socket.emit (events.js:67:17)
    at Array.0 (net.js:319:25)
    at EventEmitter._tickCallback (node.js:192:41)

What could be the cause of this error?

You are most likely still trying to connect to a service on that port.

The default behaviour is to attempt to connect and when it can't it dies with an error like the one you see. This is for saftey reasons since a connection error 90% of the time means a downed DB (like it does in your case) which is bad and shouldn't be ignored.

The easiest way to overcome this error is to try catch the connection block so as to understand when a connection error has been received and do something about it.