Connection to MongoDB ends abruptly

I have connected our MongoDB instance to retool as a resource.
Everything is working fine, but if a query has not been made to the DB for some time (Users edit the table typically for > 15 minutes before clicking "save"), the save handler query fails with "cannot use a session that has ended" error. This essentially means that the mongo connection has died and all the edits that the users worked on is gone.

What is the best practice to keep the connection to the DB alive for longer from within retool?

Any help would be greatly appreciated, thanks.

We are facing the exact same issue. Connection to Mongo drops after 15 mins or so. Retool can't connect to Mongo. All Retool external ips are whitelisted on the Mongo instance. It works intermittently.

As a test we have enabled all ip ranges to be able to connect to Mongo, Retool still fails to connect to mongo. It connects intermittently then it fails. If we wait 15 mins or so, it works again.

@Tech It's not an IP thing as far as I know. It is a stale connection timeout baked into your database so that the DB won't have a large number of stale connections open. Typically this is put in deliberately for Production DBs. A general workaround for this provided by services is a connection refresher that pings the DB at a certain interval (say every 10 minutes) so that the connection is not marked "stale". There is no such config in retool as of now for this from what I have seen.

As a workaround, you can have an empty query (a very light query) run automatically every 10 minutes or so. This would keep the connection active.

@tris_me
It fails while I'm middle of actively setting up a dashboard. The query works and I can see the data in the preview and the very next preview doesn't work. I don't wait 15 mins.

Hey @Tech @tirs_me! Unable to repro connection issues on the couple of test Mongo accounts I use. Can you share a bit more about the the resource and the mongo db you are using?

Namely, are you using the Standard or DNS seed connection formats?
Which mongo version are you using (3.4 or lower / 3.6 and above)?

Are you using Retool on Cloud or a self hosted instance?

Thanks!

Hi @joeBumbaca. Sure, I am using standard connection, mongo version 3.4 and below and am connecting through SSH tunneling. Let me know if any more info is needed and thanks in advance.

@tirs_me Thanks for that information.

Would also like to know if you are using Retool on Cloud or a self hosted instance?

If cloud, can you share your org's subdomain so that I can check out any logs that we might have?

In both cases, logs from your bastion host when the connection fails would be ideal as well.

Thanks!

@joeBumbaca Thanks for the reply.
In our case, it's Retool cloud.

Retool Cloud -> Mongo DB through connection string
(No Bastion host).

We are using Retool on Cloud and our org's domain is "chargely.retool.com" . I tried dwelling the bastion logs but they are very messy and thus, couldn't extract much. I'll keep looking and post here if I spot the logs when the retool failed.