rust-pcap / pcap

Rust language pcap library
Apache License 2.0
620 stars 144 forks source link

0.9 seem broken using tokio stream #187

Closed Stargateur closed 2 years ago

Stargateur commented 3 years ago

I update from 0.8 to 0.9 and just test today, my code capture one packet but nothing else.

git diff:

-    cap.filter("port sip").context(PacketCap)?;
+    cap.filter(&OPTIONS.filter, true).context(PacketCap)?;

I even try remove filter, nothing work expect go back to 0.8. If anyone can confirm ?

DanielRussell commented 3 years ago

Hello @Stargateur. I've not seen this problem before. Is your code available, or do you have a minimal reproducible test case you can share?

Do you know if your application only stops receiving packets, or does it lock up entirely?

The included example seems to work fine.

Stargateur commented 3 years ago

I try to repro from the example end up that it's using tokio::main that trigger the problem:

#[tokio::main]
async fn main() {
    let stream = start_new_stream().await;

    let fut = stream.for_each(move |s| {
        println!("{:?}", s);
        futures::future::ready(())
    });
    fut.await;
}

Example use mono thread run time, mine use multi thread.

Do you know if your application only stops receiving packets, or does it lock up entirely?

The rest of my async code run properly. But my code that run pcap only capture 1 or sometime two then is never call again.

DanielRussell commented 3 years ago

Thank you for the hint! I've made a failing test case and will see if I can track down what needs to be fixed.

DanielRussell commented 3 years ago

@Stargateur, can you please try the most recent tokio-multithread branch on my fork and let me know if it fixes your issues?

Stargateur commented 3 years ago

Look it's working, the example work, and my application to capture sip packet seem ok too. Thank for the fix. Be able to use tokio 1 is great.

stappersg commented 3 years ago

On Sat, Oct 02, 2021 at 03:17:11AM -0700, Antoine wrote:

... my application to capture sip packet seem ok too. Thank for the fix.

And is that fix in this git repository?

It is OK to beat me up with the URL of the merge request that I missed.

Regards Stappers

DanielRussell commented 3 years ago

@stappersg the previous fix was only in my fork as I waited for feedback from @Stargateur. PR #189 contains the fix, and should be clean enough to merge

Wojtek242 commented 2 years ago

I have merged @DanielRussell fix and pushed an update to 0.9.1 to crates.io