Handling MongoDB disconnect/reconnects from Node

后端 未结 3 1460
不知归路
不知归路 2020-12-15 14:15

When my MongoDB connection is idle for a few minutes, the next request ends in error. From the mongo command line client, it looks like this:

&g         


        
3条回答
  •  感情败类
    2020-12-15 14:55

    You want to look at the docs for the Server object

    http://mongodb.github.com/node-mongodb-native/api-generated/server.html#server

    Especially the socketOptions where you can set keepAlive and the connection timeouts. By default keepalive is off and timeout is 0 or never which means the os default socket timeout is in effect (varies from os to os). Keep alive will send a packet once in awhile down the tcp socket connection to keep it alive. Sometimes firewalls are badly configured and don't send an end packet when they close a connection leaving the connection dead and in limbo which is what the monoglabs people are talking about (more often than not to be honest they are horribly configured).

提交回复
热议问题