Reputation: 105
In my micronaut application I am using websockets but socket connection is timing out after every 5 minutes i want to customize this value. In micronaut documentation this configuration is given:
micronaut:
server:
idle-timeout: 30m # 30 minutes
But this config is also not working. Can anyone help?
Upvotes: 3
Views: 1905
Reputation: 160
I think that the server config would affect every connection you open - not just the socket TCP. The solution for me was to implement a "ping-pong" or "heartbeat" feature - basically a message send from the client to the server and back over a fixed interval. I would send "ping" every x
minutes and the back end would respond with "pong". Although this does the job at keeping the connection open, I'm certain it's not a good solution for every project.
Also, the documentation here under Connection Timeouts
section says:"...By default Micronaut will timeout idle connections that have no activity after 5 minutes. Normally this is not a problem as browsers will automatically reconnect WebSocket sessions...", which was not the case for me as well.
Upvotes: 0
Reputation: 105
Had to use this configuration:
server:
idle-timeout: 60m
read-idle-timeout: 60m
write-idle-timeout: 60m
Turns out Micronaut sends a disconnect event for every one of these settings so we have to update timeout for all three values.
Upvotes: 5