Skip to content

fix(corekit): let Windows reopen SeekableReader's buffer file (#2098) - #2105

Merged
JarryShaw merged 1 commit into
mainfrom
fix/2098-seekable-reader-tempfile
Oct 23, 2026
Merged

JarryShaw merged 1 commit into
mainfrom
fix/2098-seekable-reader-tempfile

Conversation

@JarryShaw

Copy link
Copy Markdown
Owner

What is the purpose of your pull request?

  • fix — bug fixes

Description of your pull request and other information

Closes #2098. With buffer_save=True and no buffer_path, SeekableReader created a NamedTemporaryFile and later reopened it by name in read/read1/readline/peek. Windows refuses that while the file is open, so --buffer-save failed with PermissionError: [Errno 13].

  • Fix: the file is created with mkstemp, and close() closes and deletes it. A weakref.finalize deletes it if the reader is collected unclosed. A caller-given buffer_path is never deleted, and a failed open releases both the descriptor and the file.
  • Test: test_io_buffer_save_tempfile_2098_unit makes a second open of an open NamedTemporaryFile raise, as Windows does. Without the fix it raises PermissionError: [Errno 13]. The test also pins that the temp file is gone after close(), after collection and after an Extractor(buffer_save=True) run, and that a caller's buffer_path survives. tests/corekit/test_io.py passes.

With buffer_save and no buffer_path the reader made a NamedTemporaryFile and
read it back by name, which Windows refuses while it is open. The file is now
made with mkstemp and removed on close, or by a weakref.finalize at
collection; a caller's buffer_path is never removed.
@JarryShaw JarryShaw added bug Issues reporting a defect (set by the bug report template; a default, not an assessment) review: running A cross-review is in flight against the current head - no verdict yet labels Oct 23, 2026
@JarryShaw

Copy link
Copy Markdown
Owner Author

GOOD TO GO at a4ef1fc88 (Sonnet review).

  • Test: test_the_buffer_reads_back_where_a_temporary_file_cannot_be_reopened fails with io.py reverted and passes with the fix. The other four pass on both sides; they guard against regressions, since NamedTemporaryFile used to auto-delete. Neighbouring io and extraction tests pass.
  • Probes:
    • A double close() is safe.
    • close() after the file was already unlinked is safe.
    • An unclosed reader that is garbage-collected has its file removed.
    • The finalize holds only the file and the path, not the reader.
    • A caller's buffer_path is kept.
    • A failed open leaves nothing behind.
  • Nit, no change: if the underlying stream's close() raises, the temp file waits for garbage collection.
  • UNVERIFIED: finalisation on GraalPy and PyPy.

@JarryShaw JarryShaw added review: good-to-go Cross-review at the current head says ready; CI state is separate and removed review: running A cross-review is in flight against the current head - no verdict yet labels Oct 23, 2026
@JarryShaw JarryShaw moved this to In review in PyPCAPKit Oct 23, 2026
@JarryShaw

Copy link
Copy Markdown
Owner Author

Ready to merge at a4ef1fc88.

  • Review: the Sonnet review is GOOD TO GO.
  • CI: every blocking check passed (Required checks passed SUCCESS). The 3.8–3.10 KTLO legs carry no warnings.
  • Ordering: the tests/corekit plain-unittest leg fails, with 34 failures and 31 errors, but it fails identically on plain main (aeb4aadd3). The failure set diffs as equal, every one an enum-lookup test, so it is pre-existing and not from this PR. CI has no corekit ordering leg; both points are tracked in test(corekit): the corekit plain-unittest ordering leg fails on main, and CI never runs it #2115, and a fix is in progress. The new and changed tests here pass under pytest.

This closes #2098.

@github-actions

Copy link
Copy Markdown
Contributor

Coverage: 91.53% (unit tier, Python 3.15, a4ef1fc88, Unit Tests run success)

Package Statements Missed Branches Partial Cover
pcapkit (top level) 104 4 20 2 95.16%
pcapkit/const 19599 880 2618 866 92.12%
pcapkit/corekit 2580 75 814 37 96.46%
pcapkit/dumpkit 282 3 102 3 98.44%
pcapkit/foundation 2930 23 1022 25 98.79%
pcapkit/interface 138 4 52 3 96.32%
pcapkit/protocols 17414 219 4574 185 98.14%
pcapkit/toolkit 869 36 298 10 95.20%
pcapkit/utilities 473 7 136 5 98.03%
pcapkit/vendor 4432 1988 1018 167 51.87%

Per-file detail: the coverage-html artifact of this run.

@JarryShaw
JarryShaw merged commit 70dea91 into main Oct 23, 2026
65 checks passed
@github-project-automation github-project-automation Bot moved this from In review to Done in PyPCAPKit Oct 23, 2026
@JarryShaw
JarryShaw deleted the fix/2098-seekable-reader-tempfile branch October 23, 2026 21:52
@JarryShaw JarryShaw removed the review: good-to-go Cross-review at the current head says ready; CI state is separate label Oct 23, 2026
@JarryShaw JarryShaw added this to the PyPCAPKit v1.5 milestone Oct 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Issues reporting a defect (set by the bug report template; a default, not an assessment)

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

fix(corekit): SeekableReader reopens its NamedTemporaryFile by name, which Windows refuses

1 participant