fix: decouple AppendRows/stream context from per-flush lifecycle - #11
Merged
Merged
Conversation
yuzone
force-pushed
the
fix/decouple-append-context-from-flush-lifecycle
branch
from
June 30, 2026 05:12
737aa34 to
2623c5d
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
In the default (at-least-once) path,
AppendRowsand managed stream creation were passed the per-flush context. Since appends are acknowledged asynchronously on a later flush, canceling the flush context at flush end aborted the managed writer's internal retry/reconnect (managedwritercheckspendingWrite.reqCtxinlockingAppend) and immediately terminalized dynamically-scaled streams (ms.ctxderives from the creation context). As a result, a transient connection failure escalated into a permanent failure storm (massAppending data ... failed, latency pinned at the flush timeout) that only recovered after a pod restart.This PR decouples the append/stream lifetime from the per-flush lifecycle by introducing an instance-scoped context.
Changes
out_writeapi.goonly:instanceCtx/instanceCancel(instance-lifetime context) tooutputConfig.FLBPluginInit: replace the throwawayinitCtxwithcontext.WithCancel(context.Background()); use it for client creation,getDescriptors, and the initialbuildStream. CallinstanceCancel()on every error return path to avoid context leaks.sendRequestDefault: passconfig.instanceCtxtoAppendRows(primary fix).createNewStreamDynamicScaling: passconfig.instanceCtxtobuildStreamso scaled streams are not terminalized at flush end.sendRequestRetries: useconfig.instanceCtxfor stream rebuild as well.FLBPluginExitCtx: callinstanceCancel()only after pending responses are drained and streams/client are closed, to avoid aborting in-flight appends.