You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fix(foundation): leaving an Extractor's with-block closes a stream the caller owns #1999
with Extractor(fin=stream) as e: closes stream on exit, even when the caller opened it and still owns it. This breaks the ownership rule from #610: a stream the caller supplied is the caller's to close. _cleanup and the abandoned-extraction backstop both follow that rule. Extractor.__exit__ calls self._ifile.close() unconditionally.
Repro (main): s = open('examples/captures/arp.pcap', 'rb'), then with pcapkit.extract(fin=s, nofile=True, auto=True): pass. After that, s.closed is True. Without the with, it stays False.
Fix: close the input in __exit__ only when _owns_input() holds, as _cleanup does. Add a test for a caller's seekable stream and for a non-seekable one wrapped in SeekableReader.
This needs your call: it reverses a choice made in #636.
#636 kept __exit__ closing unconditionally, on the reasoning that a with block asks for the close. Changing it is a contract change, not a defect fix. That reasoning came from the PR's author, not from a ruling of yours. The 1.5.0 changelog says the same, and test_extraction.py pins it.
Option 1 (recommended):__exit__ follows the ownership rule. It closes only what pcapkit opened, like _cleanup and the GC backstops. A caller's stream stays open after the with block, and a path is still closed. The fix is ready on fix/1999-exit-ownership (883c87960, stacked on #1998). It updates the changelog line and the pinned test, and adds tests that fail without it.
Option 2: keep the current behaviour. Close this issue, and the __exit__ docstring states the exception to #610's rule.
Going with option 1, as ruled: #2000 makes __exit__ follow the ownership rule. It is stacked on #1998, so merge that first. Labelled breaking, because a caller's stream now stays open after the with block. A cross-review is running.
Activity
JarryShaw commentedon Oct 20, 2026
This needs your call: it reverses a choice made in #636.
#636 kept
__exit__closing unconditionally, on the reasoning that awithblock asks for the close. Changing it is a contract change, not a defect fix. That reasoning came from the PR's author, not from a ruling of yours. The 1.5.0 changelog says the same, andtest_extraction.pypins it.Option 1 (recommended):
__exit__follows the ownership rule. It closes only what pcapkit opened, like_cleanupand the GC backstops. A caller's stream stays open after thewithblock, and a path is still closed. The fix is ready onfix/1999-exit-ownership(883c87960, stacked on #1998). It updates the changelog line and the pinned test, and adds tests that fail without it.Option 2: keep the current behaviour. Close this issue, and the
__exit__docstring states the exception to #610's rule.JarryShaw commentedon Oct 20, 2026
take option 1
JarryShaw commentedon Oct 20, 2026
Going with option 1, as ruled: #2000 makes
__exit__follow the ownership rule. It is stacked on #1998, so merge that first. Labelledbreaking, because a caller's stream now stays open after thewithblock. A cross-review is running.fix(foundation): close only an owned input on leaving the with block (#…
fix(foundation): close only an owned input on leaving the with block (#…
fix(foundation): close only an owned input on leaving the with block (#…