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.

Web Socket subscription drops initial messages

See original GitHub issue

Hi @davesmith00000 šŸ‘‹šŸ½

I’ve been debugging all day (going crazy really šŸ˜„) a subtle issue with the Web Socket subscriptions and I now have a lead, but unfortunately not a fix yet.

As far I can observe, once a connection is established, there seems to be a delay in registering the subscription and so messages that arrive immediately are never processed by Tyrian, but they can be seen in the browser’s developer console.

msg

I think the last version where this was working as expected was 0.3.2, so shame on me, I haven’t properly tested my application to find this issue sooner.

I tried to minimize the example using the Echo Server from the examples. For example, there is a message saying ā€œConnection madeā€¦ā€, which doesn’t get to Tyrian subs.

Long shot, but do you recall if this message was being processed on versions 0.3.2 and lower?

On my application, I temporarily added a delay before sending the Attached message, but it’s not a long-term solution.


Unrelated question: Is there a Matrix bridge for the Discord channel?

Issue Analytics

  • State:open
  • Created a year ago
  • Comments:9 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
davesmith00000commented, Sep 28, 2022

Evening @gvolpe šŸ‘‹

Mixed success. šŸ˜„

Discord:

t2bot looks easy enough, but I have no idea what I’m doing with Matrix itself. I’ll try and read up more tomorrow.

WebSockets

So it’s late, and I could be making this up at this point, but here’s roughly what I think happens:

  1. User fires a cmd to connect to the web socket.
  2. Cmds are lazy, so it’s popped on a queue.
  3. When evaluated, the command creates a connection immediately, instantly fires any opening socket messages, and then returns an object containing the connection and the subs the user needs to register - but they have NOT been registered yet.
  4. It emits another lazy, queued command saying ā€œconnectedā€ which the user listens for.
  5. The user grabs the event and saves the socket object in their model somewhere.
  6. <At this point we get lucky, because the engine runs cmds then subs, if it was the other way around I think the process would do nothing until a new event went through the system 😬>
  7. The user takes the stored details from the model and registers the subs in the list.
  8. <At this point, we might have a deadlock waiting for an event to trigger re-evaluation of this subs list… but that’s speculation… and luckily some impatient tester sends a message so the subs list is evaulated.>
  9. By this time any initial messages are long gone assuming a responsive server.

If I’m right, the fix is to not create/open the connection until we’re also in a position to register the subs in the same pass. Somehow.

It’s a theory. I’ll see if I can prove it, but probably not until the weekend unfortunately…

1reaction
davesmith00000commented, Sep 28, 2022

Unrelated question: Is there a Matrix bridge for the Discord channel?

Given I only vaguely know what the means the answer is almost certainly, no, but happy to look into it?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Create reliable Websocket clients - Microsoft Learn
Websocket client connections may drop due to intermittent network issue and when connections drop, messages will also be lost.
Read more >
WebSocket messages are lost while client is reconnecting
Sometimes the underlying websocket connection is lost and the client needs to reconnect and subscribe to the topic again (with 10 seconds timeout)....
Read more >
WebSocket Messages - Twitch Developers
Defines the first message that the EventSub WebSocket server sends after ... WebSocket server sends your client when an event that you subscribe...
Read more >
WebSockets - A Conceptual Deep Dive - Ably Realtime
The WebSocket protocol created new possibilities for communication over the Internet and opened the door to a truly realtime web.
Read more >
26. WebSocket Support - Spring
Notably the first Internet Explorer version to support WebSocket is version 10 (see ... Spring Framework 4 includes a new spring-messaging module with...
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