MongoSocketReadException: Prematurely reached end of stream (after a period of inactivity)

前端 未结 6 1908
Happy的楠姐
Happy的楠姐 2020-12-05 02:34

I get this error on a find call (default Java Driver) after a period of inactivity. I tried to add a manual heartbeat (writing to a capped collection), but it d

6条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-05 03:33

    I found it in some documentation:

    For long running applications, it is often prudent to enable "keepAlive" with a number of milliseconds. Without it, after some period of time you may start to see "connection closed" errors for what seems like no reason.

    Check if this helps. When you connect to mongoDB you can pass socket options to it. I am from node background we use following options to keep it alive.

    server: {
            socketOptions: {
                keepAlive: 100,
                connectTimeoutMS: 30000
            }
        }
    

    Hope this helps!!

提交回复
热议问题