stomp-js / stompjs

Javascript and Typescript Stomp client for Web browsers and node.js apps
Apache License 2.0
738 stars 80 forks source link

Still seeing retry after a successful connection. #615

Open louisparks opened 7 months ago

louisparks commented 7 months ago

Hello, I am running into a situation where sometimes I am getting the the beforeConnect callback coming in just after (1s) the onConnect callback (at least as seen in the logs). It then continues to call beforeConnect over and over again every 5secs (reconnectDelay=5000). Funny thing is, the websocket is actually connected to the broker and can receive messages from the broker. I am terribly confused. Any ideas? I am on 6.1.2

2023-11-09 04:22:25.628-06:00 (worker1 ) [debug] WebsocketService : Websocket Connected { command: 'CONNECTED', headers: { 'heart-beat': '45000,45000', version: '1.2' }, _binaryBody: {}, isBinaryBody: true, escapeHeaderValues: false, skipContentLengthHeader: false } 2023-11-09 04:22:25.629-06:00 (worker1 ) [debug] WebsocketService : successfull websocket re-connect after 5540 retries. 2023-11-09 04:22:25.630-06:00 (worker1 ) [debug] WebsocketService : susbcribing to device topic 2023-11-09 04:22:25.631-06:00 (worker1 ) [debug] WebsocketService : subscribed to device topic 2023-11-09 04:22:25.632-06:00 (worker1 ) [debug] WebsocketService : starting heartbeat with server 2023-11-09 04:22:28.025-06:00 (worker1 ) [debug] WebsocketService : detected retry loop, will retry connection 2023-11-09 04:22:28.093-06:00 (main ) [debug] MainIpcHandlers : IPC_EVENT_CONNECT_STATUS_CHANGE status change { online: false } 2023-11-09 04:22:28.094-06:00 (render1 ) [debug] renderPreload : connection status change { online: false } 2023-11-09 04:22:28.096-06:00 (render1 ) [info] app.tsx : connection status change in app { online: false }

 this.wsclient.beforeConnect = async () => {
      await this.loadConnectionDetails();
      this.wsclient.brokerURL = this.brokerUrl();

      //Are we in a retry loop?
      if (this.connectionRetryCount == 0) {
        log.debug(`detected retry loop, will retry connection`);
      }
      this.connectionRetryCount++;
    };

    this.wsclient.onConnect = (frame) => {
      log.debug("Websocket Connected", frame);
      if (this.connectionRetryCount > 0) {
        log.debug(
          `successfull websocket re-connect after ${this.connectionRetryCount} retries.`
        );
      }
      // Subscribing to topics and starting heartbeat after connection
      this.subscribeToTopics();
      this.beginHeartbeat();
      this.connectionRetryCount = 0;
      this.lastServerConnectTime = new Date();
      this.initialized = true;
    };
kum-deepak commented 2 months ago

Maybe you have already resolved this issue. If not please provide the following: