Skip to content

fix(benchmark): treat a pcap engine's loader OSError as unmeasured, not fatal (#2129) - #2131

Merged
JarryShaw merged 1 commit into
mainfrom
fix/2129-benchmark-loader-oserror
Oct 24, 2026
Merged

JarryShaw merged 1 commit into
mainfrom
fix/2129-benchmark-loader-oserror

Conversation

@JarryShaw

Copy link
Copy Markdown
Owner

What is the purpose of your pull request?

  • fix — corrects a defect

Description of your pull request and other information

Closes #2129.

  • Cause: in the pcap_ct environment, import pcap raises OSError on macOS (dlopen(libc.so.6 …)) and on Windows (Cannot find npcap/wpcap.dll). pcap_ct already reports that through its own unsupported_reason(), but pypcap does not. So extract(engine='pypcap') raises, and _unavailable re-raised the error because the message lacks libpcap. The whole environment exited.
  • Fix: a new _loader_failure(engine) in preflight, for the engines backed by _pcap_backend.DISTRIBUTIONS only, asks _pcap_backend.probe(). If the module is installed but fails to import, the engine becomes an explained row carrying the real OSError. The 'libpcap' in str(exc) wording check is gone, so an OSError reading the capture is always a real failure.
  • README: one Troubleshooting sentence. This PR does not touch the parts ci(benchmark): run the engine benchmark on Actions and post the report to Discussions (#2125) #2128 owns.
  • Tests: TestLoaderFailure in examples/benchmark/test_harness.py fakes each runner's loader error. All 6 tests fail against main's benchmark.py, and the file gives 122 passed with the fix.
  • Not fixed here: the library itself has the same gap. PyPCAP._reason_for does not report an unusable pcap module the way PCAP_CT._reason_for does. That is filed separately.

…ot fatal (#2129)

pcap-ct's libpcap loader raises OSError on macOS (dlopen libc.so.6) and
Windows (npcap/wpcap.dll) with wording the harness did not match, so
preflight("pypcap") re-raised and the whole pcap_ct environment exited.

- preflight now asks the pcap module's import, through the probe the
  engines share, for pypcap and pcap_ct; a loader failure becomes the
  reason with its own message, and the other engines carry on
- drop the "libpcap"-wording OSError match in _unavailable, so an
  OSError reading the capture stays a real failure
- tests for both messages, and a README troubleshooting line
@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 24, 2026
@JarryShaw

Copy link
Copy Markdown
Owner Author

GOOD TO GO at eff7ff6c7 (Sonnet review).

  • Root cause: confirmed from the run's logs. preflight('pypcap') died in _extract with dlopen(libc.so.6 …) on macOS and with Cannot find npcap/wpcap.dll on Windows. Neither message contains libpcap.
  • _loader_failure: it probes only the _pcap_backend.DISTRIBUTIONS engines, with the same "installed but unusable" condition as PCAP_CT._reason_for. _purge leaves no pcap module behind, so pypcap → pcap_ct → pypcap all return the same reason.
  • Linux: no regression. A fake pcap raising Cannot find libpcap.so library still becomes an explained row for both engines.
  • Tests: all 6 new tests fail on main's benchmark.py, and the harness gives 122 passed.
  • Library: the reviewer reproduced the gap. extract(engine='pypcap') raises the OSError where engine='pcap_ct' warns and falls back. I'm filing it separately.

@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 24, 2026
@JarryShaw JarryShaw moved this to In review in PyPCAPKit Oct 24, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Coverage: 91.55% (unit tier, Python 3.15, eff7ff6c7, 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 2589 75 816 37 96.48%
pcapkit/dumpkit 282 3 102 3 98.44%
pcapkit/foundation 2969 23 1036 25 98.80%
pcapkit/interface 138 4 52 3 96.32%
pcapkit/protocols 17418 219 4574 185 98.14%
pcapkit/toolkit 869 36 298 10 95.20%
pcapkit/utilities 498 7 144 5 98.13%
pcapkit/vendor 4432 1988 1018 167 51.87%

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

@JarryShaw

Copy link
Copy Markdown
Owner Author

Ready to merge at eff7ff6c7.

  • Review: the Sonnet review is GOOD TO GO.
  • CI: every blocking check passed (Required checks passed SUCCESS), and the 3.8–3.10 KTLO legs carry no warnings.
  • Base: the head sits directly on main 8fdc2fb33.
  • Ordering: no plain-unittest ordering leg applies, because the change is confined to examples/benchmark/. examples/benchmark/test_harness.py gives 122 passed.

This closes #2129.

@JarryShaw
JarryShaw merged commit 270f114 into main Oct 24, 2026
67 checks passed
@github-project-automation github-project-automation Bot moved this from In review to Done in PyPCAPKit Oct 24, 2026
@JarryShaw
JarryShaw deleted the fix/2129-benchmark-loader-oserror branch October 24, 2026 04:33
@JarryShaw JarryShaw removed the review: good-to-go Cross-review at the current head says ready; CI state is separate label Oct 24, 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(benchmark): a pcap engine's loader OSError kills the whole environment on macOS and Windows

1 participant