Skip to content

Add unsubscribe to RobustSubscription / Provider #39

@LeoPatOZ

Description

@LeoPatOZ

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:

  1. It calls provider.unsubscribe(id) on the underlying RootProvider
  2. This removes the subscription from the pubsub frontend's internal tracking
  3. However, the RobustSubscription still holds its own Subscription<N::HeaderResponse> object
  4. 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:

  1. Cancels the internal subscription
  2. 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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions