Skip to content

[Feature] Fix race condition on subscription setup #2187

@mattsse

Description

@mattsse

Component

provider, pubsub

Describe the feature you would like

fix for #1601 which outlined a race condition when we retrieve the subscription for the first time, this is because we drop the the rx here:

let (tx, _rx) = broadcast::channel(channel_size);

and by the time

let mut sub = ws_provider.root().get_subscription(sub_id).await?;

we only subscribe to new values.

RawSubscription { rx: self.tx.subscribe(), local_id: self.local_id }

we can fix this race in two ways

  1. either change the set up in such a way that
request.set_is_subscription();
let sub_id = request.await?;

this directly awaits into a subscription

  1. don't drop the receiver until the first subscription is retrieved

we can do both 1 and 2 imo, 2 should fix this issue right away

@yash-atreya

Additional context

No response

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Type

No type

Projects

Status

Completed

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions