scapy icon indicating copy to clipboard operation
scapy copied to clipboard

Fix sniff timeout when libpcap select returns readable with no packets

Open T3pp31 opened this issue 6 months ago • 1 comments

Summary

  • When sniff(..., timeout=N) uses a libpcap socket, select may report the capture fd as readable even when no BPF-matched packets are available; a blocking pcap_next_ex in recv() could then stall past the sniff timeout (same class as #74).
  • Timed sniff loops now call nonblock_recv() when the socket supports it, via a nonblock flag on session recv().
  • Adds a mock regression test that simulates libpcap always returning the socket from select while nonblock_recv() yields no packet.

Fixes #4590

Test plan

  • [x] New regression test: sniff timeout with select-ready but empty pcap socket (#4590) in test/regression.uts
  • [x] Manual verification: mock socket completes within ~1s with timeout=1, blocking recv() never called
  • [ ] CI (UTscapy on Linux with libpcap)

Made with Cursor

T3pp31 avatar Jun 01 '26 13:06 T3pp31

Hi & thanks for the PR !

It has great performance implications to use a non blocking read instead of a blocking one. I am therefore not sure that this is the proper way of tackling the issue.

gpotter2 avatar Jun 02 '26 08:06 gpotter2