Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

client_listener: Explicitly queue outgoing messages to guarantee order #28

Closed
wants to merge 1 commit into from

Conversation

progval
Copy link
Contributor

@progval progval commented Aug 25, 2023

Spawning a task on each event to send implicitly used tokio as an unbounded queue that doesn't actually preserve order.

This could cause issues, such as ConnectionData being sent after the first message, which violates assumptions down the line.

Spawning a task on each event to send implicitly used tokio as an unbounded
queue that doesn't actually preserve order.

This could cause issues, such as ConnectionData being sent after the first
message, which violates assumptions down the line.
@@ -106,6 +103,16 @@ impl ListenerProcess {
}

select! {
event = self.event_out_buffer_rx.recv() =>
{
let event_sender = Arc::clone(&self.event_sender);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need for these clone operations if you're not spawning a subtask

{
let event_sender = Arc::clone(&self.event_sender);
let shutdown_flag = Arc::clone(&self.shutdown_flag);
if let Err(e) = event_sender.send(&event.unwrap()).await {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sending here will still block the main task if send() blocks, which brings back the deadlock issue that caused me to spawn sends in the first place.

If we're going to use an unbounded channel to make sure that this task never blocks, then there needs to be a separate task that reads it and forwards to the socket; if we're doing the socket writes in this task then we can do them directly and don't need the extra channel.

@progval
Copy link
Contributor Author

progval commented Aug 26, 2023

Rewritten in #29 (from scratch, though they turned out to look quite similar)

@progval progval closed this Aug 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants