Skip to content

fix(redis): expect a single ack count for targeted broadcast with ack - #782

Open
LiamCarPer wants to merge 1 commit into
Totodore:mainfrom
LiamCarPer:fix/redis-targeted-broadcast-with-ack
Open

fix(redis): expect a single ack count for targeted broadcast with ack#782
LiamCarPer wants to merge 1 commit into
Totodore:mainfrom
LiamCarPer:fix/redis-targeted-broadcast-with-ack

Conversation

@LiamCarPer

Copy link
Copy Markdown
Contributor

Fixes a redis adapter bug i noticed while working on #774 (thanks for asking for a separate PR for it).

Motivation

When BroadcastOptions::server_id is set (broadcasting to a remote socket), redis sends the ack request to that server only, but the expected ack count was always server_count - 1.
With 3+ servers only one server answers, so the ack stream does not terminate cleanly and waits for the request timeout instead.

With 2 servers the targeted count happens to be equal to server_count - 1, which is why this went unnoticed: the existing remote_socket_emit_with_ack test never awaits the acks.

Solution

get_res already handles a targeted request this way, so I mirrored it in broadcast_with_ack:

let remote_serv_cnt = if opts.server_id.is_none() {
    self.server_count().await?.saturating_sub(1)
} else {
    1
};

Added
remote_socket_emit_with_ack_targeted_terminates in crates/socketioxide-redis/tests/sockets.rs: spawns 3 servers, emits with ack to the remote sockets (echoing the acks from the fake clients) and asserts the stream is terminated right after the ack. It fails before the fix and passes after.
No behavior or wire format change for the non targeted case.

When `BroadcastOptions::server_id` is set, the request is sent to this
server only, so only one server answers. The expected ack count was still
`server_count - 1`, making the ack stream wait for the request timeout
before terminating when there are 3+ servers. With 2 servers the targeted
count happens to be equal to `server_count - 1`, which is why it went
unnoticed.

`get_res` already handles a targeted request this way.

Adds a regression test with 3 servers asserting the targeted ack stream
terminates right after the ack.
@codspeed-hq

codspeed-hq Bot commented Sep 11, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 87 untouched benchmarks


Comparing LiamCarPer:fix/redis-targeted-broadcast-with-ack (720311b) with main (9a10442)

Open in CodSpeed

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.

1 participant