Skip to content

when a bayeuxClient.disconnect is issued, server is not responding with disconnected message. #2074

Open

Description

@aakashpanjwani

CometD version(s) 8.0.7

Java version & vendor (use: java -version) JDK 17

Description
when a bayeuxClient.disconnect is issued, server is not responding with disconnected message.

How to reproduce?
call bayeuxClient.disconnect()
OR
call bayeuxclient.disconnect(Long.valueOf(10000)

Debug logs below -

2025-05-02 16:17:52.205 [DEBUG] [HttpClient@cb1c58c-34] [  ] Received messages [{ext={replay=true, payload.format=true}, minimumVersion=1.0, clientId=day1sc0vfn63hbuc905br2117l5f, supportedConnectionTypes=[long-polling], channel=/meta/handshake, id=1, version=1.0, successful=true}]
2025-05-02 16:17:52.207 [DEBUG] [HttpClient@cb1c58c-34] [  ] Processing {ext={replay=true, payload.format=true}, minimumVersion=1.0, clientId=day1sc0vfn63hbuc905br2117l5f, supportedConnectionTypes=[long-polling], channel=/meta/handshake, id=1, version=1.0, successful=true}
2025-05-02 16:17:52.210 [DEBUG] [HttpClient@cb1c58c-34] [  ] State updated: HANDSHAKING -> HANDSHAKEN
2025-05-02 16:17:52.216 [DEBUG] [HttpClient@cb1c58c-34] [  ] Sending messages [{ext={replay={/topic/cFields=46}}, clientId=day1sc0vfn63hbuc905br2117l5f, channel=/meta/subscribe, id=4, subscription=/topic/cFields}]
2025-05-02 16:17:52.218 [DEBUG] [HttpClient@cb1c58c-34] [  ] Started waiting for message replies, 30000 ms, task@d8d4d18
2025-05-02 16:17:52.220 [DEBUG] [HttpClient@cb1c58c-34] [  ] Sent message {ext={replay={/topic/cFields=46}}, clientId=day1sc0vfn63hbuc905br2117l5f, channel=/meta/subscribe, id=4, subscription=/topic/cFields}
2025-05-02 16:17:52.222 [DEBUG] [HttpClient@cb1c58c-34] [  ] State updated: HANDSHAKEN -> CONNECTING
2025-05-02 16:17:52.224 [DEBUG] [HttpClient@cb1c58c-34] [  ] Scheduled connect in 0+0 ms
2025-05-02 16:17:52.225 [DEBUG] [pool-2-thread-1] [  ] Connecting, transport cuConsumer$1@14c18a6a
2025-05-02 16:17:52.225 [DEBUG] [pool-2-thread-1] [  ] Sending messages [{clientId=day1sc0vfn63hbuc905br2117l5f, advice={timeout=0}, channel=/meta/connect, id=5, connectionType=long-polling}]
2025-05-02 16:17:52.225 [DEBUG] [pool-2-thread-1] [  ] Sending /meta/connect {clientId=day1sc0vfn63hbuc905br2117l5f, advice={timeout=0}, channel=/meta/connect, id=5, connectionType=long-polling}
2025-05-02 16:17:52.226 [DEBUG] [pool-2-thread-1] [  ] Started waiting for message replies, 30000 ms, task@41858029
2025-05-02 16:17:52.226 [DEBUG] [pool-2-thread-1] [  ] Sent connect {clientId=day1sc0vfn63hbuc905br2117l5f, advice={timeout=0}, channel=/meta/connect, id=5, connectionType=long-polling}
2025-05-02 16:17:52.227 [DEBUG] [pool-3-thread-1] [  ] Sending messages [{clientId=e5p1i3jbj6iex99t63q7s33lq58y, advice={timeout=0}, channel=/meta/connect, id=6, connectionType=long-polling}]
2025-05-02 16:17:52.228 [DEBUG] [pool-3-thread-1] [  ] Sending /meta/connect {clientId=e5p1i3jbj6iex99t63q7s33lq58y, advice={timeout=0}, channel=/meta/connect, id=6, connectionType=long-polling}
2025-05-02 16:17:52.228 [DEBUG] [pool-3-thread-1] [  ] Started waiting for message replies, 30000 ms, task@760d7e9e
2025-05-02 16:17:52.228 [DEBUG] [pool-3-thread-1] [  ] Sent connect {clientId=e5p1i3jbj6iex99t63q7s33lq58y, advice={timeout=0}, channel=/meta/connect, id=6, connectionType=long-polling}
2025-05-02 16:17:52.229 [DEBUG] [HttpClient@cb1c58c-34] [  ] Notifying threads in waitFor()
2025-05-02 16:17:52.313 [DEBUG] [HttpClient@cb1c58c-37] [  ] Stored cookie Immutable@4069d9f1[BrowserId=_1zWuydwEfCk9DdyDf9-IA; domain=.salesforce.com; Expires=Sat, 2 May 2026 16:17:52 GMT; Max-Age=31536000; path=/; SameSite=None; Secure=true]
2025-05-02 16:17:52.321 [DEBUG] [HttpClient@cb1c58c-37] [  ] Cancelled waiting for message replies, task@d8d4d18
2025-05-02 16:17:52.321 [DEBUG] [HttpClient@cb1c58c-37] [  ] Received messages [{clientId=day1sc0vfn63hbuc905br2117l5f, channel=/meta/subscribe, id=4, subscription=/topic/cFields, error=400::The replayId {46} you provided was invalid.  Please provide a valid ID, -2 to replay all events, or -1 to replay only new events., successful=false}]
2025-05-02 16:17:52.321 [DEBUG] [HttpClient@cb1c58c-37] [  ] Processing {clientId=day1sc0vfn63hbuc905br2117l5f, channel=/meta/subscribe, id=4, subscription=/topic/cFields, error=400::The replayId {46} you provided was invalid.  Please provide a valid ID, -2 to replay all events, or -1 to replay only new events., successful=false}
2025-05-02 16:17:52.322 [INFO ] [HttpClient@cb1c58c-37] [  ] cuConsumer: Not subscribed to : /topic/cFields
2025-05-02 16:17:52.323 [INFO ] [HttpClient@cb1c58c-37] [  ] cuConsumer: Got Error ... {clientId=day1sc0vfn63hbuc905br2117l5f, channel=/meta/subscribe, id=4, subscription=/topic/cFields, error=400::The replayId {46} you provided was invalid.  Please provide a valid ID, -2 to replay all events, or -1 to replay only new events., successful=false}
2025-05-02 16:17:52.323 [INFO ] [HttpClient@cb1c58c-37] [  ] cuConsumer: Disconnecting cuClient ...

We should get a
channel=/meta/disconnect successful=true <------- at this place or atleast after the wait of 5 seconds

2025-05-02 16:17:52.323 [INFO ] [HttpClient@cb1c58c-37] [ ] cuConsumer: Sleeping for 5 seconds before reconnect.

Activity

  1. sbordet commented on May 2, 2025

    @sbordet
    Member

    What exact vendor/version are the server and the client?

    The logs are incomplete, or do not show the client attempting to send a /meta/disconnect to the server.

    Can you show what your code does when it receives a subscription failure?

  2. aakashpanjwani commented on May 2, 2025

    @aakashpanjwani
    Author

    Thank you for quick reply @sbordet

    Whenever the consumer gets a 400/401/403 error... it will attempt to disconnect the client with below code.

    private void disconnect() {
    
        if (!running.compareAndSet(true, false)) {
          return;
        }
    
        if (bayeuxclient != null && bayeuxclient.isConnected()) {
          
          if (bayeuxclient.disconnect(Long.valueOf(disconnectWaitMs))) {
    
            bayeuxclient.waitFor(1000, BayeuxClient.State.DISCONNECTED);
    
            if (bayeuxclient.isDisconnected()) {
    
              LOG.info("Disconnected...");
              
            } else {
              
              bayeuxclient.disconnect();
            }
          }
        }
        bayeuxclient = null;
      }
  3. aakashpanjwani commented on May 2, 2025

    @aakashpanjwani
    Author

    Scenario is -
    during app startup - I'm using the max replay id to subscribe to the topic - now this max replay id is out of the retention window hence I'm getting a error as below :

    2025-05-02 15:57:30.673 [INFO ] [HttpClient@9499643-39] [ ] Got Error ... {clientId=d5q19x6kfx8ie20pudv1hnkcr67v, channel=/meta/subscribe, id=219, subscription=/topic/cuFields, error=400::The replayId {46} you provided was invalid. Please provide a valid ID, -2 to replay all events, or -1 to replay only new events., successful=false}

    now when I get this error, I catch it using a Listener and then initiate a disconnect.

    this disconnect is not responded by the server.

  4. sbordet commented on May 2, 2025

    @sbordet
    Member

    The code you posted above does would not log the line:

    2025-05-02 16:17:52.323 [INFO ] [HttpClient@cb1c58c-37] [  ] cuConsumer: Disconnecting cuClient ...
    

    Are you sure that's the code you're running?

    BayeuxClient.isConnected() only returns true if a /meta/connect has been sent, so I would not use that, but rather:

    private void disconnect() {
        if (!running.compareAndSet(true, false)) {
            return;
        }
    
        if (bayeuxclient != null && !bayeuxclient.isDisconnected()) {
            bayeuxClient.disconnect(Long.valueOf(disconnectWaitMs));
            LOG.info("Disconnected");
        }
    
        bayeuxclient = null;
    }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions