Skip to content

Possible out-of-order delivery of server->client messages #446

Open
@krajj7

Description

@krajj7

Hi Peter,

I noticed that the buffering of server->client messages that Sente does can randomly cause out-of-order delivery under certain conditions.

For example when a thread quickly sends two messages like this via Sente using the send-fn:
N1 larger message
N2 small message

The client might receive them in the order N2 N1.

From looking at the code, around this point the flush-buffer! function seems problematic:

(let [buffered-evs-ppstr (pack packer buffered-evs)]

If a message happens to take a longer time to pack (say 50 ms), or the thread just stalls for whatever reason after picking up a message form the buffer, other threads executing flush-buffer! can pick up and send newer messages before the older thread is done.

If none of the messages use {:flush? true}, the stall would probably have to be longer than send-buf-ms-ws (30 ms by default) to potentially cause a problem. In case message N2 used {:flush? true} and N1 didn't, then it's probably not even needed to stall for as long as send-buf-ms-ws, depending on timing (send N2 just after N1 is pulled from the buffer).

The current workaround for me is to use {:flush? true} for the subset of messages that are ordering-critical.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions