Skip to content

automaton: drop stopped children from the spawn listener - #5129

Open
KernelClint wants to merge 1 commit into
secdev:masterfrom
KernelClint:automaton-drop-stopped-children
Open

automaton: drop stopped children from the spawn listener#5129
KernelClint wants to merge 1 commit into
secdev:masterfrom
KernelClint:automaton-drop-stopped-children

Conversation

@KernelClint

Copy link
Copy Markdown
Contributor

Automaton.spawn() runs a listener that accepts connections and starts a child automaton for each
one, tracking them in a clients list so they can be shut down with the listener.

Children are appended at
scapy/automaton.py:1041-1047
and never removed. Each new connection walks the entire list and calls destroy() again on every
child that has already stopped. Over a run of short-lived connections the list only grows, and the
work done per connection grows with it — the total is quadratic in the number of connections
served. The stopped children stay reachable too, so their memory is not reclaimed.

The change removes each stopped child once it has been destroyed, iterating a copy so removal
during iteration is safe:

-        for c in self.clients:
+        for c in list(self.clients):
             if not c[1].isRunning():
                 c[1].destroy()
+                self.clients.remove(c)

Live children are untouched, so listener shutdown still reaches all of them.

The added regression accepts several connections, stops them, and asserts the list holds only the
running children. Without the removal it fails.

Performance was measured on one computer, before and after the fix: accepting a connection while a
child is still running took 6,652.7 ns before and 6,669.2 ns after. Repeat runs moved by about 2%,
so that difference is smaller than the test can distinguish.

@codecov

codecov Bot commented Sep 1, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 80.63%. Comparing base (b3bbcc8) to head (b877242).

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #5129      +/-   ##
==========================================
- Coverage   80.63%   80.63%   -0.01%     
==========================================
  Files         390      390              
  Lines       96936    96937       +1     
==========================================
  Hits        78168    78168              
- Misses      18768    18769       +1     
Files with missing lines Coverage Δ
scapy/automaton.py 80.15% <100.00%> (-0.18%) ⬇️

... and 7 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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 this pull request may close these issues.

1 participant