Problem
Currently, RobustProvider::unsubscribe(id) does not properly cancel a RobustSubscription.
Root Cause
Alloy's PubSubFrontend::unsubscribe (source) only sends a PubSubInstruction::Unsubscribe to the backend, which removes the subscription from local tracking. It does not make an eth_unsubscribe RPC call.
When RobustProvider::unsubscribe(sub_id) is called:
- It calls
provider.unsubscribe(id) on the underlying RootProvider
- This removes the subscription from the pubsub frontend's internal tracking
- However, the
RobustSubscription still holds its own Subscription<N::HeaderResponse> object
- The stream continues to receive blocks because the underlying websocket subscription is still active
Expected Behavior
After calling unsubscribe, the stream should return None (closed).
Proposed Solution
RobustSubscription needs its own unsubscribe method that:
- Cancels the internal subscription
- Signals the stream to close
Options:
- Add an
unsubscribe() method directly on RobustSubscription
- Use a cancellation token/channel that
RobustProvider::unsubscribe can signal
- Track active subscriptions in
RobustProvider and notify them on unsubscribe
Problem
Currently,
RobustProvider::unsubscribe(id)does not properly cancel aRobustSubscription.Root Cause
Alloy's
PubSubFrontend::unsubscribe(source) only sends aPubSubInstruction::Unsubscribeto the backend, which removes the subscription from local tracking. It does not make aneth_unsubscribeRPC call.When
RobustProvider::unsubscribe(sub_id)is called:provider.unsubscribe(id)on the underlyingRootProviderRobustSubscriptionstill holds its ownSubscription<N::HeaderResponse>objectExpected Behavior
After calling
unsubscribe, the stream should returnNone(closed).Proposed Solution
RobustSubscriptionneeds its ownunsubscribemethod that:Options:
unsubscribe()method directly onRobustSubscriptionRobustProvider::unsubscribecan signalRobustProviderand notify them on unsubscribe