question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

A way to flush/deliver messages before disconnecting

See original GitHub issue

Hey folks,

We are currently sending some messages, and based on a flag disconnect the clients if the conversation/process is finished. If so, we call client.disconnect() on it to make sure the client no longer keeps the connection open.

However, this is causing client to disconnect even before receiving the messages. I was hoping to have a client.disconnect(flushBeforeDisconnectBoolean) or a simple method as client.flush that sends all messages by blocking the call.

Is there a way to send messages and then wait for it to be delivered before disconnecting the client ?

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
sbordetcommented, Dec 4, 2018

@jaypatel512 this is already possible in CometD 4:

serverChannel.publish(null, data, Promise.complete((r, x) -> serverSession.disconnect()));

If you like Java’s CompletableFuture, use Promise.Completable (a subclass of Java’s CompletableFuture):

Promise.Completable<Boolean> completable = new Promise.Completable<>();
serverSession.deliver(null, "/channel", data, completable);
completable.thenAccept(b -> serverSession.disconnect());
0reactions
sbordetcommented, Dec 11, 2018

You have to clarify what you mean exactly by “disconnect”. CometD disconnect message? TCP disconnect?

The server side promise cannot wait for the browser. The server side promise is completed as soon as the TCP write succeeds (or fails). Whether the message will arrive to the client, that is unknown to the server, and the server cannot wait. It may still happen, however, that the messages and the disconnect message (from server to client) travel onto 2 different TCP connections and therefore there is no guarantee of ordering between the messages and the disconnect message.

The ack extension guarantees ordered delivery.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Sending Disconnect Messages #533 - vis2k/Mirror - GitHub
I need this in uMMORPG as well. right now I have a workaround where I send an error message without disconnecting, and the...
Read more >
Connecting to and disconnecting from a queue manager - IBM
They can use the MQDISC call to disconnect from that queue manager. Following an IMS call that establishes a syncpoint, and before processing...
Read more >
Add or remove your phone number in Messages or FaceTime
On your iPhone: Go to Settings > Messages and make sure that iMessage is on. You might need to wait a moment for...
Read more >
Django Channels - Not Able to Send Messages on Disconnect
1. Each WebsocketConsumer has a websocket_disconnect function defined which removes the groups currently assigned to the websocket before ...
Read more >
Slack Connect: Disconnect from an organization
You can disconnect from an organization to end all communication with them in Slack Connect channels and direct messages (DMs).
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found