Skip to content

No AsyncSniffer.resluts after .stop(False) is called #4890

@D-Shelef

Description

@D-Shelef

Brief description

When I call AsyncSniffer.stop(join=False), if timeout is passed to the object initialization captured packets cannot be accessed till that timeout passed even if I call the .stop() method.

I believe the cause is the following:

  • I pass timeout to AsyncSniffer.
  • Because of that in ._run() the variable remain has the value stoptime - time.monotonic().
  • It is passed to select_func() as the timeout.
  • If no packet is received the function is now blocking till the timeout has passed (give or take).

That means if I put relatively large timeout just in case I cannot see the result till this timeout passes.
I want to be able to stop the capture when I wish to (with plausible synchronization time).

Scapy version

2.7.0

Python version

3.14

Operating system

macOS 26.2

Additional environment information

I also got it with python 3.10, scapy 2.6.1 on a Linux image (it did behave a bit differently).

How to reproduce

I run the following code:

import scapy.all as sa
import time

for i in range(10):
   t1 = sa.AsyncSniffer(count=3, filter="ip host 1.2.3.4", timeout=10)
   t1.start()
   time.sleep(1)
   if t1.running:
       t1.stop(join=False)
       t1.thread.join(timeout=1)
       time.sleep(3)
       print(f"was running,  thread.is_alive == {t1.thread.is_alive()}, running == {t1.running}, result == {t1.results}")
   else:
       print("was not running")

Actual result

The output I got:

was running,  thread.is_alive == True, running == True, result == None
was running,  thread.is_alive == True, running == True, result == None
was running,  thread.is_alive == True, running == True, result == None
was running,  thread.is_alive == True, running == True, result == None
was running,  thread.is_alive == True, running == True, result == None
was running,  thread.is_alive == True, running == True, result == None
was running,  thread.is_alive == True, running == True, result == None
was running,  thread.is_alive == True, running == True, result == None
was running,  thread.is_alive == True, running == True, result == None
was running,  thread.is_alive == True, running == True, result == None

Expected result

To be able to see the captured packets when I stop the sniff
The sniffing thread should die
.running should be False
All the obvious stuff

Related resources

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions