mikemintz / rethinkdb-websocket-server

Node.js WebSocket server that proxies to RethinkDB. Supports query validation.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Automatic reconnect on db connection interruption

coffenbacher opened this issue · comments

If the connection to the database gets interrupted (e.g. database is restarted), the server seems to crash permanently.

It would be great if the server could reconnect when the connection is available again.

For example, this stacktrace is what happens to the Chat example when the database is restarted (and in perpetuity until the websocket server is restarted).

22:21:18.676 172.17.0.5:54391 Error in sessionCreator
ReqlDriverError: Connection is closed.
    at ReqlDriverError.ReqlError [as constructor] (/app/node_modules/rethinkdb/errors.js:23:13)
    at new ReqlDriverError (/app/node_modules/rethinkdb/errors.js:68:50)
    at TcpConnection.Connection._start (/app/node_modules/rethinkdb/net.js:413:13)
    at /app/node_modules/rethinkdb/ast.js:142:29
    at Get.TermBase.run (/app/node_modules/rethinkdb/ast.js:131:12)
    at AuthManager.js:17:47
    at tryCatcher (/app/node_modules/bluebird/js/release/util.js:16:23)
    at Promise._settlePromiseFromHandler (/app/node_modules/bluebird/js/release/promise.js:497:31)
    at Promise._settlePromise (/app/node_modules/bluebird/js/release/promise.js:555:18)
    at Promise._settlePromiseCtx (/app/node_modules/bluebird/js/release/promise.js:592:10)
    at Async._drainQueue (/app/node_modules/bluebird/js/release/async.js:130:12)
    at Async._drainQueues (/app/node_modules/bluebird/js/release/async.js:135:10)
    at Immediate.Async.drainQueues [as _onImmediate] (/app/node_modules/bluebird/js/release/async.js:16:14)
    at processImmediate [as _immediateCallback] (timers.js:383:17)

Based on that stack trace, and my understanding of the code, I think this is specific to the chat example and other similar examples. It's the connection set up manually in index.js as opposed to the proxied connections that rethinkdb-websocket-server provides.

So before implementing auto-reconnect in rethinkdb-websocket-server, we'd first have to provide an abstraction as opposed to having the application developer manually connect for validations.

I'm not sure yet what the best way to do that is, but it's worth exploring.

In the meantime, I think if developers use rethinkdbdash when connecting from their backend, it provides auto-reconnect out of the box.

Great, I think rethinkdbdash should solve my immediate issue. Thanks!