File tree Expand file tree Collapse file tree 1 file changed +15
-6
lines changed Expand file tree Collapse file tree 1 file changed +15
-6
lines changed Original file line number Diff line number Diff line change @@ -329,13 +329,22 @@ func (a *API) connectToWS(idx int) {
329
329
a .WebsocketRespLock .Unlock ()
330
330
331
331
go func (ws * chan []byte ) {
332
+ // Send keep alive messages every 20 seconds
333
+ // There is at least one proxy service in our cluster that closes the connection after 30 seconds of inactivity
334
+ // This is to prevent the connection beeing closed
335
+ keepAliveTicker := time .NewTicker (time .Second * 20 )
336
+ keepAliveBody := []byte ("pnig" )
332
337
for {
333
- // TODO: if the response fails to send data might get lost.
334
- // It would be nice if the response is retried when WriteMessage fails
335
- resp := <- a .WebsocketResp [idx ]
336
- err := c .WriteMessage (1 , resp )
337
- if err != nil {
338
- fmt .Println ("unable to write ws response:" , err )
338
+ select {
339
+ case <- keepAliveTicker .C :
340
+ c .WriteMessage (websocket .PingMessage , keepAliveBody )
341
+ case resp := <- a .WebsocketResp [idx ]:
342
+ // TODO: if the response fails to send data might get lost.
343
+ // It would be nice if the response is retried when WriteMessage fails
344
+ err := c .WriteMessage (1 , resp )
345
+ if err != nil {
346
+ fmt .Println ("unable to write ws response:" , err )
347
+ }
339
348
}
340
349
}
341
350
}(listenChan )
You can’t perform that action at this time.
0 commit comments