1

I am using sails 1.0.0-37 and sails-mongo 1.0.0-10 . When sails is lifted, if mongo db server is up and running, everything is okay. If mongo db goes down, and the node.js tries to access the mongo db as part of a functionality and it times out, an internal server error is shown to the user. This is all okay. However, when mongo comes back up, sails no longer reconnects to it and throws out this error:

" AdapterError: Unexpected error from database adapter: fn called its error exit with:{ MongoError: Topology was destroyed } "

I set autoReconnect: true as part of mongodb adapter's options.. This reconnection works only if node.js does not try to access mongodb server while it is down.. How to fix this? Otherwise it's not possible to use sails 1.0 and sails-mongo in prod?

Kalana Demel
  • 3,220
  • 3
  • 21
  • 34

1 Answers1

2

I faced the same problem, and here is the explanation and solution:

If you don't set "reconnectTries", it will be set 30 by default. After 30 attempts, sails couldn't connect to mongo and throw "Topology was destroyed".

For me, the solution is to set reconnectTries to Number.MAX_VALUE

default: {
  adapter: 'sails-mongo',
  url: 'mongodb://admin:admin123@127.0.0.1:27017/datastore?authSource=admin',
  reconnectTries: Number.MAX_VALUE,
  reconnectInterval: 1000
}

I hopes that helped.

Murilo
  • 21
  • 4