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

FollowStreamFinalizedHeads doesn't work properly for non-reconnecting backend #1808

Closed
niklasad1 opened this issue Oct 3, 2024 · 0 comments · Fixed by #1817
Closed

FollowStreamFinalizedHeads doesn't work properly for non-reconnecting backend #1808

niklasad1 opened this issue Oct 3, 2024 · 0 comments · Fixed by #1817

Comments

@niklasad1
Copy link
Member

niklasad1 commented Oct 3, 2024

FollowStreamFinalizedHeads is used both for reconnecting and non-reconnecting rpc clients currently which doesn't work properly for non-reconnecting because this stream assumes that after the stop event it will continue/be restarted.

This is not true for non reconnecting backend when the stop event is fired the backend is closed. Thus, if one subscribes to finalized blocks and the backend is stopped then the stream will never return and wait forever.

So in order fix this we would need to inject a flag here whether the backend is reconnecting or not, or alternatively make FollowStreamDriverSubscription aware of this in some way.

Example to reproduce this:

Open terminal 1

substrate-node --dev
# Wait for the node to start

Open terminal 2

Run the following code

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    tracing_subscriber::fmt::init();

    let rpc = RpcClient::from_url("ws://localhost:9944".to_string()).await?;
    let backend: ChainHeadBackend<PolkadotConfig> =
        ChainHeadBackendBuilder::default().build_with_background_driver(rpc.clone());
    let api = OnlineClient::from_backend(std::sync::Arc::new(backend)).await?;

    let mut blocks_sub = api.blocks().subscribe_finalized().await?.take(100);

    while let Some(block) = blocks_sub.next().await {
        let block = block?;

        let block_number = block.number();
        let block_hash = block.hash();

        println!("Block #{block_number} ({block_hash})");
    }

    Ok(())
}

Open terminal 3

pkill substrate-node

At this point (when substrate-node is stopped) then the finalized head stream should be terminated but it isn't....

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 a pull request may close this issue.

1 participant