0

I have problems with my open connections with RethinkDB. If errors occur in my Sinatra back-end app methods, the connection with Rethink is not closed. Therefore the number of open connections slowly increases.

This results in too many open connections, resulting in the error:

Error: the RethinkDB database is not available

So questions is twofold: First to help me out right now; how can I close the open Rethink connections? Secondly, how can I avoid the build-up of open connections? Should I open a connection for every call to my back-end, or should I just open a connection with Rethink once when my app is initiated?

Rethink looks promising, but a little help would be greatly appreciated!

Fritzz
  • 656
  • 6
  • 27

2 Answers2

0

You can close a connection by calling .close on the connection object returned by connect. It should be OK to open one connection per call to your back-end as long as you close those connections when you're done. (In general RethinkDB can support a lot of open connections at once, unless it's running on a low-resource system or the OS is configured to limit the number of open connections.)

mlucy
  • 5,249
  • 1
  • 17
  • 21
  • Problem is that I dont have a connection object anymore when an error is raised. I could probably build this disconnection in the error catcher, but I wonder how I can now close them after the connections are built but never closed without an connection object. – Fritzz Sep 20 '15 at 10:18
  • Thats why you should close the connection as soon as you don't need it anymore, when you still have the connection object. – mhutter Sep 21 '15 at 08:24
  • So it is impossible to close connections after you don't have the connection object anymore? No admin or server-side solution either? That would also be an answer... – Fritzz Sep 22 '15 at 12:38
  • 1
    I don't think there's a way to do that right now. I opened a GitHub issue: https://github.com/rethinkdb/rethinkdb/issues/4873 . One option if you really need to kill these connections is to use `tcpkill` (or something similar) to terminate the connection from outside both programs. – mlucy Sep 22 '15 at 17:17
  • Thanks @mlucy. I think that should be the answer. If you post it as an answer I'll mark that as the solution. – Fritzz Sep 24 '15 at 12:02
0

I don't think there's a way to do that in RethinkDB right now. I opened a GitHub issue: github.com/rethinkdb/rethinkdb/issues/4873 . One option in the meantime is to use tcpkill (or something similar) to terminate the connection.

mlucy
  • 5,249
  • 1
  • 17
  • 21