Skip to content

test(datastore): recognise COMMIT after a statement close in the retry-safe fault proxy - #4927

Merged
tphakala merged 2 commits into
mainfrom
fix/retry-safe-test-commit-packet
Oct 28, 2026
Merged

tphakala merged 2 commits into
mainfrom
fix/retry-safe-test-commit-packet

Conversation

@tphakala

@tphakala tphakala commented Oct 28, 2026 •

Copy link
Copy Markdown
Owner

Description

TestSaveDetection_RetrySafeMarkerMatchesCommitOutcome_MySQL failed on every run on mariadb:11.8 and intermittently on the other server legs, which turned the database-tests (mariadb-11.8) job red on main. It is a test bug, not a product bug.

The test sits a fault-injecting TCP proxy between the app and the server and detects the COMMIT of the save transaction to drop it or to lose its reply. The detector looked only at the first packet of each TCP read. The MySQL driver writes the close of a prepared statement right before the COMMIT, so one read can hold both packets, the COMMIT is then not recognised, no fault is injected, and Save returns nil where the test expects an error. Whether the two packets arrive in one read or two is a scheduling race, so the test passed only by chance.

isCommitPacket now walks every packet in the read and matches the COMMIT in any of them, skipping empty packets and ignoring a partial trailing packet. A table-driven test covers COMMIT alone, after a statement close, after an empty packet, lower case, a non-COMMIT query, empty, short and partial buffers, and payloads past one and two length bytes. The product code is unchanged; when the fault does fire the existing assertions hold on every server.

Tests: the save test passes 5 of 5 runs on mariadb:11.8, mariadb:10.11 and mysql:8.4, and 3 of 3 on mariadb:11.4 and mysql:9.7.4; before the change it failed 3 or 4 of 4 runs on the first four. golangci-lint with the integration tag reports 0 issues.

Related issue

None.

Checklist

  • I have read the Contributing Guidelines
  • Tests pass locally (task test and/or npm test)
  • Linters are clean (task lint and/or npm run check:all)
  • New exports and user-facing changes are documented
  • Feature PRs only: the feature was discussed with the maintainer first (linked above), and I will maintain it after it is merged, as described in Feature Ownership

Licensing (required)

BirdNET-Go is moving from CC BY-NC-SA 4.0 to an OSI-approved open source license (AGPL-3.0). See the tracking issue #4243. Contributions cannot be merged until the author agrees to this, because contributors keep copyright and the current inbound license does not grant relicensing rights.

  • I have read #4243 and I agree that my contribution is licensed under CC BY-NC-SA 4.0 and that I grant the maintainer a perpetual, irrevocable right to relicense it under any OSI-approved open source license (AGPL-3.0), as described in the Relicensing Grant. I understand my PR will not be merged until this box is checked.

Summary by CodeRabbit

  • Tests
    • Expanded coverage for MySQL transaction packet handling, including combined packets, varying packet lengths, and incomplete input. No user-facing behavior changes are included in this update.

…y-safe fault proxy

The fault proxy decided whether a client write was the COMMIT by looking
only at the first packet of each TCP read. The driver writes
COM_STMT_CLOSE right before COMMIT, so a single read could hold both
packets. The COMMIT was then missed, no fault was injected and Save
returned nil, which made the test flaky on every MySQL image and
deterministic on mariadb:11.8.

isCommitPacket now walks every packet in the buffer, skipping empty
packets and ignoring a partial packet at the end of the read. A
table-driven test pins the packet walk.
…yte packet lengths

The retry-safe fault proxy test built its COM_STMT_CLOSE packet from bare
numbers and only used payloads short enough for a one-byte length. Name the
command byte and statement id length, and add rows with payloads that need
the second and third length bytes before the COMMIT.
@coderabbitai

coderabbitai Bot commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review.

Recent review info
Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Essentials
  • Run ID: 457635fd-f986-4694-b19a-bd93bceb3d5f
Commits

Reviewing files that changed from the base of the PR and between 873ef8d and 616be51.

Files selected for processing: 1
  • internal/datastore/v2only/save_retry_safe_mysql_test.go

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 4 remain after this review.

Walkthrough

The MySQL test helper now scans complete packets in a buffer and detects case-insensitive, whitespace-trimmed COMMIT queries. Added tests cover packet framing, concatenated packets, and incomplete input.

Changes

MySQL commit packet detection

Layer / File(s) Summary
Packet scanning and validation
internal/datastore/v2only/save_retry_safe_mysql_test.go
The helper scans complete packets for COMMIT queries. Tests cover standalone and concatenated packets, multi-byte payload lengths, non-COMMIT packets, and incomplete input.

Priority: Low

Estimated code review effort: 2 (Simple) | ~8 minutes

Change: Other

Suggested labels: pkg:datastore

Merge Risk: Minimal · up to 616be

The remaining split-read edge case does not establish a new merge-blocking risk for this test-only change.

Pre-merge checks: Passed 3 · Failed 2

Failed Failed checks: 2 warnings

Check name Status Explanation Resolution
Description check Warning The description explains the failure, root cause, implementation, test coverage, and results. However, all checklist items remain unchecked, including the required relicensing agreement. Update the checklist to reflect completed work. Check the required relicensing agreement only after confirming acceptance, and check the contributing-guidelines, test, lint, documentation, and feature-PR items as applicable.
Docstring Coverage Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documenta… Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 3 passed
Check name Status Explanation
Title check Passed The title clearly and specifically identifies the main change: updating the retry-safe fault proxy test to recognize COMMIT after a statement close.
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Docstring Coverage

Explanation

Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 2 functions across 1 files.

Resolution

Write docstrings for the functions missing them to satisfy the coverage threshold.

Finishing Touches: 💡 1
📝 Generate docstrings: 💡
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Comment @coderabbitai help to get the list of available commands.

@gitar-bot

gitar-bot Bot commented Oct 28, 2026 •

Copy link
Copy Markdown
Code Review ✅ Approved

🟢 Low risk · The test-only proxy now detects COMMIT after preceding packets, fixing fault-injection coverage without changing application behavior.

Fixes the retry-safe fault proxy so isCommitPacket checks every packet in a TCP read instead of only the first, letting the COMMIT after a prepared statement close be recognised when both arrive in one read. Test-only change with a table-driven test covering empty, partial, and multi-length-byte packets. No issues found.

Verification

Rules No rules evaluated

Functional validation Not enabled

Set up

For more verification details, comment gitar display:verbose.

Options

Auto-apply is off → Gitar will not commit updates to this branch.
Display: compact → Showing compact verification results.

Comment with these commands to change the behavior for this request:

Auto-apply Compact
gitar auto-apply:on         
gitar display:verbose         

Was this helpful? React with 👍 / 👎 | Powered by Gitar — free for open source

@coderabbitai coderabbitai Bot added the pkg:datastore Data storage and database operations label Oct 28, 2026
@tphakala
tphakala merged commit f1ba095 into main Oct 28, 2026
29 checks passed
@tphakala
tphakala deleted the fix/retry-safe-test-commit-packet branch October 28, 2026 19:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pkg:datastore Data storage and database operations

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant