@@ -159,28 +159,34 @@ public boolean addWebSocketScope(WebSocketScope webSocketScope) {
159159 scopes .forEach ((sName , wsScope ) -> {
160160 log .trace ("start pinging scope: {}" , sName );
161161 wsScope .getConns ().forEach (wsConn -> {
162- // ping connected websocket
163- if (wsConn .isConnected ()) {
164- log .debug ("pinging ws: {} on scope: {}" , wsConn .getWsSessionId (), sName );
165- try {
166- wsConn .sendPing (PING_BYTES );
167- } catch (Exception e ) {
168- log .debug ("Exception pinging connection: {} connection will be closed" , wsConn .getSessionId (), e );
169- // if the ping fails, consider them gone
170- wsConn .close ();
162+ try {
163+ // ping connected websocket
164+ if (wsConn .isConnected ()) {
165+ log .debug ("pinging ws: {} on scope: {}" , wsConn .getWsSessionId (), sName );
166+ try {
167+ wsConn .sendPing (PING_BYTES );
168+ } catch (Exception e ) {
169+ log .debug ("Exception pinging connection: {} connection will be closed" , wsConn .getSessionId (), e );
170+ // if the connection isn't connected, remove them
171+ wsScope .removeConnection (wsConn );
172+ // if the ping fails, consider them gone
173+ wsConn .close ();
174+ }
175+ } else {
176+ log .debug ("Removing unconnected connection: {} during ping loop" , wsConn .getSessionId ());
177+ // if the connection isn't connected, remove them
178+ wsScope .removeConnection (wsConn );
171179 }
172- } else {
173- log .debug ("Removing unconnected connection: {} during ping loop" , wsConn .getSessionId ());
174- // if the connection isn't connected, remove them
175- wsScope .removeConnection (wsConn );
180+ } catch (Exception e ) {
181+ log .warn ("Exception in WS pinger" , e );
176182 }
177183 });
178184 log .trace ("finished pinging scope: {}" , sName );
179185 });
180186 // sleep for interval
181187 try {
182188 Thread .sleep (websocketPingInterval );
183- } catch (InterruptedException e1 ) {
189+ } catch (InterruptedException e ) {
184190 }
185191 } while (!scopes .isEmpty ());
186192 // reset ping future
0 commit comments