Skip to content

fix(loki.write): Prevent panic on failed update - #7116

Open
kalleep wants to merge 2 commits into
mainfrom
kalleep/fix-loki-write-consumer-panic
Open

kalleep wants to merge 2 commits into
mainfrom
kalleep/fix-loki-write-consumer-panic

Conversation

@kalleep

@kalleep kalleep commented Sep 16, 2026

Copy link
Copy Markdown
Contributor

Brief description of Pull Request

No longer panic on a failed update.

Pull Request Details

Before if we could not successfully create a client during an update the next entry this component got would trigger a panic since c.consumer would be nil.

The naive fix would be to do a nil check in consumeEntry and just return if it was nil but this would silently drop entries. So instead we take consumer and consumerReady under a read lock. If consumer is nil we wait on this channel. This will stop the pipeline until either a successful update have been made or component is stopped. I also added a retry for loki.ErrConsumerStopped since we will only get this error if a client consumer is stopped while we try to enqueue entry and it's safe for us to retry when we have a new consumer.

Issue(s) fixed by this Pull Request

Notes to the Reviewer

PR Checklist

  • Documentation added
  • Tests updated
  • Config converters updated
  • This pull request was substantially generated with AI assistance (see the GenAI policy)

@kalleep
kalleep requested a review from a team as a code owner September 16, 2026 10:02
@kalleep
kalleep requested a balanced review from Copilot September 16, 2026 10:03

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Retrying fanout delivery can duplicate entries already accepted by an earlier endpoint.

Get a fresh assessment by requesting another Copilot review.

Pull request overview

Prevents loki.write from panicking after failed updates by blocking entries until a consumer becomes available.

Changes:

  • Adds consumer readiness synchronization and stopped-consumer retries.
  • Tests failed-update recovery for WAL and non-WAL modes.
  • Refactors existing benchmarks.
File summaries
File Description
internal/component/loki/write/write.go Adds consumer lifecycle synchronization and retry logic.
internal/component/loki/write/write_test.go Adds recovery tests and reorganizes benchmarks.
Review details
  • Files reviewed: 2/2 changed files
  • Comments generated: 1
  • Review effort level: Balanced

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

_ = consumer.ConsumeEntry(ctx, e)
// Only a stopped consumer is worth waiting on. Anything else is an accepted
// entry, a canceled context while shutting down, or a failed WAL write.
if err := consumer.ConsumeEntry(ctx, e); !errors.Is(err, loki.ErrConsumerStopped) {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would say this is acceptable, it is better to risk that a entry get sent twice than always dropping it.

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.

2 participants