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

Error: Transport("Cannot send request. Internal task finished.") #647

Open
palinko91 opened this issue Jun 14, 2022 · 1 comment
Open

Error: Transport("Cannot send request. Internal task finished.") #647

palinko91 opened this issue Jun 14, 2022 · 1 comment

Comments

@palinko91
Copy link

Hello
I'm getting this error while listening for new pending transactions, or even if I'm using subscribe_logs with a filter, but right now I'm showing code example for the new pending transaction filter.

use std::env;
use tokio::*;
use web3::*;

use futures::stream::StreamExt;
use web3::contract::tokens::Tokenize;
use web3::transports::ws::WebSocket;
use web3::types::{TransactionId, Transaction, H256};

async fn list(pendingtx: H256, web3s: Web3<WebSocket>) -> Option<Transaction> {
    let tx = match web3s
        .eth()
        .transaction(TransactionId::Hash(pendingtx))
        .await
    {
        Ok(Some(tx)) => return Some(tx),
        _ => {
            return None;
        }
    };
}

#[tokio::main]
async fn main() -> web3::Result {
    // Loading the .env file
    dotenv().expect("Failed to read .env file");

    // Make the node connection
    let api_link = &env::var("NODE_LINK").expect("NODE_LINK must be set");
    let transport = web3::transports::WebSocket::new(&api_link).await?;
    let web3s = web3::Web3::new(transport.clone());

    // Setup the subscription stream for new pending transactions
    let mut subscription = web3s
        .eth_subscribe()
        .subscribe_new_pending_transactions()
        .await?;

    loop {
        while let Some(pendingtx) = subscription.next().await {
            let listed = list(pendingtx.unwrap(), web3s.clone());

            tokio::spawn(async move {
                match listed.await {
                    Some(result) => {
                        println!("Transaction sent from: {:?}", result.from.unwrap());
                        println!("------------------------------------------------------------");
                    }
                    None => (),
                }
            });
        }

        // If the next value in the subscription is None, then make a new subscription stream
        subscription = web3s
            .eth_subscribe()
            .subscribe_new_pending_transactions()
            .await?;
        println!("New subscription made!");
    }

    Ok(())
}

And I tried out multiple free tier node service and basically all doing the same error. Not sure because of the heavy stream not allowed in free tier or because of the web3 crate I'm experiencing this problem. But because in issues #642 had similar problem I think it's might web3 crate connected error.

@alexmikhalevich
Copy link

Any updates on the issue? I have the same problem

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

No branches or pull requests

2 participants