sniff: reap the tcpdump prefilter subprocess in offline mode#5046
Open
eugen-goebel wants to merge 1 commit into
Open
sniff: reap the tcpdump prefilter subprocess in offline mode#5046eugen-goebel wants to merge 1 commit into
eugen-goebel wants to merge 1 commit into
Conversation
sniff(offline=..., filter=...) prefilters packets through a tcpdump subprocess, but the code kept only its stdout pipe and discarded the Popen. The process was never waited on, so it lingered as a zombie and Python emitted "ResourceWarning: subprocess N is still running". Get the process with getproc=True, attach it to the PcapReader, and reap it in close(): the read pipe is closed first, a still-running tcpdump then gets a SIGTERM, and wait() collects it. This also handles early stops (count=, timeout=), where tcpdump has not finished on its own. Fixes secdev#4512 AI-Assisted: yes (Claude Opus 4.8)
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #5046 +/- ##
==========================================
+ Coverage 80.13% 80.22% +0.08%
==========================================
Files 388 388
Lines 96467 96479 +12
==========================================
+ Hits 77308 77397 +89
+ Misses 19159 19082 -77
🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
sniff(offline="file.pcap", filter="tcp")prefilters packets through atcpdumpsubprocess. The offline path builtPcapReader(tcpdump(..., getfd=True)), which returns only the stdout pipe, so thePopenobject was discarded and neverwait()ed. The process was left as a zombie, and Python 3 reports:Reproduction on current master:
Fix
As discussed in the issue, the reader now takes the process via
getproc=Trueand owns its lifetime.RawPcapReader.close()closes the read pipe, sends a still-runningtcpdumpaSIGTERM, andwait()s for it, so nothing is left behind. This also covers stopping early (count=,timeout=), wheretcpdumphas not exited on its own.Thanks to @AbhishekPandey1998 for scoping the
getprocapproach in the thread.Test
Added a regression test in
test/regression.utsthat reads a filtered offline capture (a full read and an earlycount=stop) and asserts nosubprocess ... still runningResourceWarningis emitted.Fixes #4512