Skip to content

fix(log): drain loki hook channel on shutdown - #6233

Draft
cursor[bot] wants to merge 1 commit into
masterfrom
cursor/critical-bug-investigation-fcb5
Draft

fix(log): drain loki hook channel on shutdown#6233
cursor[bot] wants to merge 1 commit into
masterfrom
cursor/critical-bug-investigation-fcb5

Conversation

@cursor

@cursor cursor Bot commented Jul 31, 2026

Copy link
Copy Markdown

What?

Drain lokiHook's buffered channel on ctx cancel before the final push, so --out loki does not lose a tail of logs that Fire already accepted.

Extracts the per-entry buffering into an appendEntry helper (same logic as before) and reuses it from a non-blocking drainQueued on the shutdown path — matching how the file log hook already drains.

Why?

Listen's ctx.Done() branch pushed only entries already copied into its msgs buffer. Anything still sitting in h.ch was dropped.

Trigger: queue log entries into the hook channel, then cancel the listen context before the run loop drains them (common at test end when many lines are still buffered).

Impact: silent loss of the final batch of --out loki logs.

TestLokiHookDrainsQueuedEntriesOnShutdown fails on unpatched code (all 100 pre-queued messages missing) and passes with this drain.

Checklist

  • I have performed a self-review of my code.
  • I have commented on my code, particularly in hard-to-understand areas.
  • I have added tests for my changes.
  • I have run linter and tests locally (make check) and all pass.

Checklist: Documentation (only for k6 maintainers and if relevant)

  • I have added the correct milestone and labels to the PR.
  • I have updated the release notes: link
  • I have updated or added an issue to the k6-documentation: grafana/k6-docs#NUMBER if applicable
  • I have updated or added an issue to the TypeScript definitions: grafana/k6-DefinitelyTyped#NUMBER if applicable

Related PR(s)/Issue(s)

Validation

  • go test ./internal/log/ -count=1 passes
  • Regression test fails without the drain and passes with it
Open in Web View Automation 

lokiHook.Listen's ctx.Done path pushed only entries already copied into
its buffer and skipped anything still queued in the channel, so a
shutdown could lose a tail of --out loki logs. Drain the channel before
the final push, matching the file hook's shutdown behavior.

Co-authored-by: Inanc Gumus <github@inanc.io>
@cla-assistant

cla-assistant Bot commented Jul 31, 2026

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

1 similar comment
@cla-assistant

cla-assistant Bot commented Jul 31, 2026

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@cursor
cursor Bot temporarily deployed to azure-trusted-signing July 31, 2026 11:21 Inactive
@cursor
cursor Bot temporarily deployed to azure-trusted-signing July 31, 2026 11:23 Inactive
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant