Skip to content

fix(traceflow): TCP flow labels are not unique, so a second flow with the same label truncates the first flow's file - #1371

Merged
JarryShaw merged 1 commit into
mainfrom
fix/1360-traceflow-label-unique
Oct 8, 2026
Merged

JarryShaw merged 1 commit into
mainfrom
fix/1360-traceflow-label-unique

Conversation

@JarryShaw

@JarryShaw JarryShaw commented Oct 7, 2026 •

Copy link
Copy Markdown
Owner
  • Searched for similar pull requests
  • Followed the coding style (make pylint, make mypy, make isort) — Makefile flags on traceflow/tcp.py: pylint 10.00/10, mypy clean, isort clean
  • make test passes, and a test case covers the change — modules listed below
  • Added a changelog entry under docs/source/changelog/ and regenerated CHANGELOG.md, if the change is user-visible — N/A, added centrally

What is the purpose of your pull request?

  • fix — corrects a defect

Description of your pull request and other information

Closes #1360

A new flow whose label an earlier flow already used now gets the next free suffix -1, -2, ... (TCP._unique_label), so it opens its own file instead of truncating the earlier one. Non-colliding labels are unchanged. The bidirectional path collided too (a new SYN on torn-down endpoints at the same timestamp), and is fixed by the same change. Visible output change: a colliding flow's label and fpout gain the suffix.

Probe (frames at t=300.0), before → after:

  • unidir FIN, ACK: two flows …-300.0, one file holding Frame 2 → …-300.0 (Frame 1) + …-300.0-1 (Frame 2)
  • bidir SYN, FIN, FIN(rev), SYN: two flows …-300.0, one file holding Frame 4 → …-300.0 (1-3) + …-300.0-1 (4)

Tests: new tests/foundation/traceflow/test_traceflow_label_unique_unit.py 4 passed; with tcp.py from origin/main, 3 failed, 1 passed (the unchanged-label case). test_tcp 15 passed, test_traceflow_base 5, data/test_models 1, integration/test_traceflow_end_to_end 7; tests/project 389 passed, 1 skipped. util/run_unittest_leg.py foundation (under a 200 MB file-size cap, per #1372): 487 tests, 2 failures, 2 errors, all pre-existing on main — the DPKT and Scapy test_pcap_output_opens_with_the_global_header (Errno 27, #1372) and both subtests of test_runtime_engines.py::PCAPEngineTests::test_pcap_run_writes_global_header_for_file_and_stream_modes.

… the same label truncates the first flow's file

A flow opened on the same endpoints at the same capture timestamp as an
earlier flow now gets the earlier label suffixed with -1, -2, ..., so each
flow keeps its own output file. Labels that do not collide are unchanged.
Both the unidirectional (resumed after FIN) and the bidirectional (new
connection on torn-down endpoints) paths collided, and both are fixed.

Closes #1360
@JarryShaw JarryShaw added fix Pull requests that fix a defect (fix: subject prefix) review: pending No verdict for the current head - never reviewed, or the head moved since the last one labels Oct 7, 2026
@JarryShaw
JarryShaw marked this pull request as ready for review October 7, 2026 21:25
@JarryShaw JarryShaw added review: running A cross-review is in flight against the current head - no verdict yet and removed review: pending No verdict for the current head - never reviewed, or the head moved since the last one labels Oct 7, 2026
@JarryShaw

Copy link
Copy Markdown
Owner Author

Cross-review verdict on 0520b0646: GOOD TO GO (Sonnet reviewed; author Opus).

  • Repro: on main, the unidirectional case (FIN then ACK at t=300.0) leaves one file holding only frame 2. The bidirectional case (connection reuse at t=300.0) leaves one file holding only frame 4, so frames 1–3 are lost. On this PR each flow gets its own file (…-300.0, …-300.0-1) and nothing is truncated.
  • No suffix collisions: _unique_label checks against every label already handed out, suffixed ones included. Five unidirectional collisions in a row gave the bare label, -1, -2, -3 and -4. Four bidirectional reuses gave the bare label and -1 to -3, each with the right frames. A collision with an already-written flow left that file intact.
  • Engines and fixtures: default, dpkt and scapy produce identical labels over all 23 captures in json and pcap, with bidirectional on and off: 276 configurations and 2,886 flows. Labels, indexes, fpout names, file lists and sizes are byte-identical to main in every configuration. No fixture has a colliding label.
  • Consumers: nothing in pcapkit/ parses a label (interface/misc.py:223 passes fpout straight through), and no test splits one on -.
  • Tests: the revert proof fails 3 of 4. tests/foundation/traceflow gives 25 passed, test_traceflow_end_to_end 7, and tests/project 389.

Nit: _labels is created lazily via __dict__.setdefault rather than in an __init__.

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

github-actions Bot commented Oct 7, 2026

Copy link
Copy Markdown
Contributor

Coverage: 88.98% (unit tier, Python 3.14, 0520b0646, Unit Tests run success)

Package Statements Missed Branches Partial Cover
pcapkit (top level) 104 4 20 4 93.55%
pcapkit/const 18777 1032 2348 843 90.27%
pcapkit/corekit 1949 84 606 20 94.91%
pcapkit/dumpkit 189 1 68 1 99.22%
pcapkit/foundation 2452 102 854 39 94.40%
pcapkit/interface 112 7 40 5 92.11%
pcapkit/protocols 16013 206 4178 177 98.06%
pcapkit/toolkit 539 74 168 3 84.58%
pcapkit/utilities 429 4 122 4 98.55%
pcapkit/vendor 4409 2359 1006 158 42.84%

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

@JarryShaw
JarryShaw merged commit ee020a7 into main Oct 8, 2026
44 checks passed
@JarryShaw
JarryShaw deleted the fix/1360-traceflow-label-unique branch October 8, 2026 00:55
@JarryShaw JarryShaw removed the review: good-to-go Cross-review at the current head says ready; CI state is separate label Oct 8, 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

fix Pull requests that fix a defect (fix: subject prefix)

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

fix(traceflow): TCP flow labels are not unique, so a second flow with the same label truncates the first flow's file

1 participant