StompJS: Случайное повторное подключение-цикл через некоторое время

#node.js #websocket #spring-websocket #java-websocket #stompjs

Вопрос:

Контекст

  • 12 (тестирование) Собственные устройства React подключены к нашему серверу через веб-сайты.
  • Случайным образом некоторые устройства перестают получать какие-либо действия сервера в течение дня.
  • Эти устройства будут застрять в петле повторного подключения.
    • Следующие действия выведут устройства из цикла:
      • Перезапуск клиентского приложения на устройствах.
      • stompSocket.deactivate() Затем последовал звонок stompSocket.activate() .
  • Во время цикла наш сервер регистрируется каждый раз, когда клиент пытается подключиться к серверу.
    • После погружения в журналы нашего сервера мы можем сделать следующий вывод:
      • Сообщение клиента CONNECT принимается сервером.
      • Сервер указывает, что клиент находится CONNECTED .
      • Примерно через 35 секунд сервер указывает, что клиент находится DISCONNECTED
  • Сердцебиения на сервере, а также на клиенте устанавливаются на 10000, 10000
  • Клиент использует @stomp/stompjs@6.1.2
  • В этом выпуске я буду масштабировать журналы одного из устройств. Журналы проблем одинаковы на всех устройствах.

Вложения

Содержание

  1. Конфигурация клиента StompJS
  2. Журналы на стороне клиента цикла повторного подключения
  3. Журналы успешного повторного подключения на стороне клиента после перезапуска нашего серверного приложения

1. Конфигурация клиента StompJS

 const stompSocket: Client = new Client({
    brokerURL: WS_URL,
    appendMissingNULLonIncoming: true,
    forceBinaryWSFrames: true,
    reconnectDelay: 5000,
    connectionTimeout: 10000,
});

stompSocket.onConnect = async (): Promise<void> => {
    stompSocket.subscribe(`/topic/${topic}/messages`, async (message: IMessage): Promise<void> => {
        // Handle messages
        ...
    }
}

stompSocket.onChangeState = async (state) => {
    logDebug(`onChangeState ${JSON.stringify(state)}`, 'WS');
};

stompSocket.onWebSocketError = async (error: any) => {
    logError(`onWebSocketError ${JSON.stringify(error)}`, 'WS');
};

stompSocket.onStompError = async (error: any) => {
    logError(`onStompError ${JSON.stringify(error)}`, 'WS');
};

stompSocket.onWebSocketClose = async (evt: any) => {
    logWarn(`onWebSocketClose(): ${JSON.stringify(evt)}`, 'WS');
};

stompSocket.onDisconnect = async (receipt: any) => {
    logWarn(`onDisconnect ${JSON.stringify(receipt)}`, 'WS');
};
    
 

2. Logs of the reconnecting loop (client-side)

  • One of the client stops receiving activity from the server, even though the server receives all the CONNECT messages from the client.
  • I can’t figure out why the CONNECT message is send after the 10000ms timeout is triggered and the connection is trying to close.
 // No previous logs in the past couple hours.
09:14:33 STOMP did not receive server activity for the last 26911ms
09:14:33 STOMP Issuing close on the websocket
09:14:43 STOMP did not receive server activity for the last 36919ms
09:14:43 STOMP Issuing close on the websocket
09:14:53 STOMP did not receive server activity for the last 46919ms
09:14:53 STOMP Issuing close on the websocket
09:15:03 STOMP did not receive server activity for the last 56923ms
09:15:03 STOMP Issuing close on the websocket
09:15:13 STOMP did not receive server activity for the last 66927ms
09:15:13 STOMP Issuing close on the websocket
09:15:23 STOMP did not receive server activity for the last 76931ms
09:15:23 STOMP Issuing close on the websocket
09:15:33 STOMP did not receive server activity for the last 86934ms
09:15:33 STOMP Issuing close on the websocket
09:15:33 WS onWebSocketError {"isTrusted":false,"message":"Socket closed"}
09:15:33 STOMP Connection closed to wss://example.com/websocket
09:15:33 WS onWebSocketClose {"isTrusted":false,"message":"Socket closed"}
09:15:33 STOMP STOMP: scheduling reconnection in 5000ms
09:15:38 STOMP Opening Web Socket...
09:15:48 STOMP Connection not established in 10000ms, closing socket
09:15:48 STOMP Issuing close on the websocket
09:15:49 STOMP Web Socket Opened...
09:15:49 STOMP
    >>> CONNECT
    accept-version:1.0,1.1,1.2
    heart-beat:10000,10000

09:16:26 STOMP Connection closed to wss://example.com/websocket
09:16:26 WS onWebSocketClose {"isTrusted":false,"code":1002,"reason":""}
09:16:26 STOMP STOMP: scheduling reconnection in 5000ms
09:16:31 STOMP Opening Web Socket...
09:16:41 STOMP Connection not established in 10000ms, closing socket
09:16:41 STOMP Issuing close on the websocket
09:16:41 STOMP Web Socket Opened...
09:16:41 STOMP
    >>> CONNECT
    accept-version:1.0,1.1,1.2
    heart-beat:10000,10000

09:17:16 STOMP Connection closed to wss://example.com/websocket
09:17:16 WS onWebSocketClose {"isTrusted":false,"code":1002,"reason":""}
09:17:16 STOMP STOMP: scheduling reconnection in 5000ms
09:17:21 STOMP Opening Web Socket...
09:17:31 STOMP Connection not established in 10000ms, closing socket
09:17:31 STOMP Issuing close on the websocket
09:17:31 STOMP Web Socket Opened...
09:17:31 STOMP
    >>> CONNECT
    accept-version:1.0,1.1,1.2
    heart-beat:10000,10000

09:18:06 STOMP Connection closed to wss://example.com/websocket
09:18:06 WS onWebSocketClose {"isTrusted":false,"code":1002,"reason":""}
09:18:06 STOMP STOMP: scheduling reconnection in 5000ms
09:18:11 STOMP Opening Web Socket...
09:18:21 STOMP Connection not established in 10000ms, closing socket
09:18:21 STOMP Issuing close on the websocket
09:18:21 STOMP Web Socket Opened...
09:18:21 STOMP
    >>> CONNECT
    accept-version:1.0,1.1,1.2
    heart-beat:10000,10000
// This keeps going for ever, until manual intervention.
 

3. Журналы успешного повторного подключения на стороне клиента после перезапуска нашего серверного приложения

  • Эти журналы показывают, чего мы должны ожидать, когда клиент пытается повторно подключиться, когда сервер не работает.
  • Серверное приложение перезапускалось между 07:04:11 и 07:05:15 .
  • Ожидается, что наш сервер apache вернется 503 при перезапуске.
  • Когда серверное приложение вернулось, клиент попытался подключиться повторно 07:05:20 . В ту же секунду соединение было установлено, и сервер вернул CONNECTED обратно.
 // No previous logs in the past couple hours.
07:04:11 STOMP Connection closed to wss://example.com/websocket
07:04:11 WS onWebSocketClose {"isTrusted":false,"code":1001,"reason":""}
07:04:11 STOMP STOMP: scheduling reconnection in 5000ms
07:04:16 STOMP Opening Web Socket...
07:04:16 WS onWebSocketError {"isTrusted":false,"message":"Expected HTTP 101 response but was '503 Service Unavailable'"}
07:04:17 STOMP Connection closed to wss://example.com/websocket
07:04:17 WS onWebSocketClose {"isTrusted":false,"message":"Expected HTTP 101 response but was '503 Service Unavailable'"}
07:04:17 STOMP STOMP: scheduling reconnection in 5000ms
07:04:22 STOMP Opening Web Socket...
07:04:22 WS onWebSocketError {"isTrusted":false,"message":"Expected HTTP 101 response but was '503 Service Unavailable'"}
07:04:22 STOMP Connection closed to wss://example.com/websocket
07:04:22 WS onWebSocketClose {"isTrusted":false,"message":"Expected HTTP 101 response but was '503 Service Unavailable'"}
07:04:22 STOMP STOMP: scheduling reconnection in 5000ms
07:04:27 STOMP Opening Web Socket...
07:04:27 WS onWebSocketError {"isTrusted":false,"message":"Expected HTTP 101 response but was '503 Service Unavailable'"}
07:04:27 STOMP Connection closed to wss://example.com/websocket
07:04:27 WS onWebSocketClose {"isTrusted":false,"message":"Expected HTTP 101 response but was '503 Service Unavailable'"}
07:04:27 STOMP STOMP: scheduling reconnection in 5000ms
07:04:32 STOMP Opening Web Socket...
07:04:32 WS onWebSocketError {"isTrusted":false,"message":"Expected HTTP 101 response but was '503 Service Unavailable'"}
07:04:32 STOMP Connection closed to wss://example.com/websocket
07:04:32 WS onWebSocketClose {"isTrusted":false,"message":"Expected HTTP 101 response but was '503 Service Unavailable'"}
07:04:32 STOMP STOMP: scheduling reconnection in 5000ms
07:04:37 STOMP Opening Web Socket...
07:04:38 WS onWebSocketError {"isTrusted":false,"message":"Expected HTTP 101 response but was '503 Service Unavailable'"}
07:04:38 STOMP Connection closed to wss://example.com/websocket
07:04:38 WS onWebSocketClose {"isTrusted":false,"message":"Expected HTTP 101 response but was '503 Service Unavailable'"}
07:04:38 STOMP STOMP: scheduling reconnection in 5000ms
07:04:43 STOMP Opening Web Socket...
07:04:43 WS onWebSocketError {"isTrusted":false,"message":"Expected HTTP 101 response but was '503 Service Unavailable'"}
07:04:43 STOMP Connection closed to wss://example.com/websocket
07:04:43 WS onWebSocketClose {"isTrusted":false,"message":"Expected HTTP 101 response but was '503 Service Unavailable'"}
07:04:43 STOMP STOMP: scheduling reconnection in 5000ms
07:04:48 STOMP Opening Web Socket...
07:04:48 WS onWebSocketError {"isTrusted":false,"message":"Expected HTTP 101 response but was '503 Service Unavailable'"}
07:04:48 STOMP Connection closed to wss://example.com/websocket
07:04:48 WS onWebSocketClose {"isTrusted":false,"message":"Expected HTTP 101 response but was '503 Service Unavailable'"}
07:04:48 STOMP STOMP: scheduling reconnection in 5000ms
07:04:53 STOMP Opening Web Socket...
07:04:54 WS onWebSocketError {"isTrusted":false,"message":"Expected HTTP 101 response but was '503 Service Unavailable'"}
07:04:54 STOMP Connection closed to wss://example.com/websocket
07:04:54 WS onWebSocketClose {"isTrusted":false,"message":"Expected HTTP 101 response but was '503 Service Unavailable'"}
07:04:54 STOMP STOMP: scheduling reconnection in 5000ms
07:04:59 STOMP Opening Web Socket...
07:04:59 WS onWebSocketError {"isTrusted":false,"message":"Expected HTTP 101 response but was '503 Service Unavailable'"}
07:04:59 STOMP Connection closed to wss://example.com/websocket
07:04:59 WS onWebSocketClose {"isTrusted":false,"message":"Expected HTTP 101 response but was '503 Service Unavailable'"}
07:04:59 STOMP STOMP: scheduling reconnection in 5000ms
07:05:04 STOMP Opening Web Socket...
07:05:04 WS onWebSocketError {"isTrusted":false,"message":"Expected HTTP 101 response but was '503 Service Unavailable'"}
07:05:04 STOMP Connection closed to wss://example.com/websocket
07:05:04 WS onWebSocketClose {"isTrusted":false,"message":"Expected HTTP 101 response but was '503 Service Unavailable'"}
07:05:04 STOMP STOMP: scheduling reconnection in 5000ms
07:05:09 STOMP Opening Web Socket...
07:05:09 WS onWebSocketError {"isTrusted":false,"message":"Expected HTTP 101 response but was '503 Service Unavailable'"}
07:05:09 STOMP Connection closed to wss://example.com/websocket
07:05:09 WS onWebSocketClose {"isTrusted":false,"message":"Expected HTTP 101 response but was '503 Service Unavailable'"}
07:05:09 STOMP STOMP: scheduling reconnection in 5000ms
07:05:14 STOMP Opening Web Socket...
07:05:15 WS onWebSocketError {"isTrusted":false,"message":"Expected HTTP 101 response but was '503 Service Unavailable'"}
07:05:15 STOMP Connection closed to wss://example.com/websocket
07:05:15 WS onWebSocketClose {"isTrusted":false,"message":"Expected HTTP 101 response but was '503 Service Unavailable'"}
07:05:15 STOMP STOMP: scheduling reconnection in 5000ms
07:05:20 STOMP Opening Web Socket...
07:05:20 STOMP Web Socket Opened...
07:05:20 STOMP
    >>> CONNECT
    accept-version:1.0,1.1,1.2
    heart-beat:10000,10000

07:05:20 STOMP
    <<< CONNECTED
    heart-beat:10000,10000
    version:1.2
    content-length:0

07:05:20 STOMP connected to server undefined 
07:05:20 TRACE ws.service.ts: stompSocket.onConnect() was called
// ...
 

Комментарии:

1. Клиент получает сообщение об ошибке 1002 WS при повторной попытке подключения. Что сервер de отправил обратно в качестве ответа при ПОДКЛЮЧЕНИИ? Есть ли вероятность, что ответ вызывает нарушение протокола?

2. Пожалуйста, смотрите приложение 3 в 07:05:20 для ответа на CONNECT . (:

3. Да, но это после перезагрузки, верно? Там ваши журналы показывают, что сервер отвечает CONNECTED сообщением, при неудачном повторном подключении оно не