Skip to content

app/vlstorage/netinsert: drain buffered data on graceful shutdown ins…#1572

Open
github-vincent-miszczak wants to merge 6 commits into
VictoriaMetrics:masterfrom
github-vincent-miszczak:fix-vlinsert-drain-on-shutdown
Open

app/vlstorage/netinsert: drain buffered data on graceful shutdown ins…#1572
github-vincent-miszczak wants to merge 6 commits into
VictoriaMetrics:masterfrom
github-vincent-miszczak:fix-vlinsert-drain-on-shutdown

Conversation

@github-vincent-miszczak

Copy link
Copy Markdown
Contributor

…tead of dropping it

vlinsert dropped in-flight buffered log blocks whenever a pod terminated (autoscaling scale-in or rolling restarts): the shutdown flush reused the already-canceled stopCh context, so requests failed immediately with "context canceled" and the data was dropped.

Thread an explicit context through the send path so the shutdown flush uses a fresh, bounded context. Buffered data is now drained to storage nodes on shutdown, bounded by the new -insert.drainTimeout flag (default 10s).

@github-vincent-miszczak
github-vincent-miszczak marked this pull request as ready for review July 3, 2026 12:54

@cubic-dev-ai cubic-dev-ai Bot 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.

1 issue found across 5 files

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment thread docs/victorialogs/CHANGELOG.md Outdated
…tead of dropping it

vlinsert dropped in-flight buffered log blocks whenever a pod terminated
(autoscaling scale-in or rolling restarts): the shutdown flush reused the
already-canceled stopCh context, so requests failed immediately with
"context canceled" and the data was dropped.

Thread an explicit context through the send path so the shutdown flush uses
a fresh, bounded context. Buffered data is now drained to storage nodes on
shutdown, bounded by the new -insert.drainTimeout flag (default 10s).
@github-vincent-miszczak
github-vincent-miszczak force-pushed the fix-vlinsert-drain-on-shutdown branch from b64086a to 6eec825 Compare July 3, 2026 13:04
@func25 func25 self-assigned this Jul 3, 2026
@github-vincent-miszczak

Copy link
Copy Markdown
Contributor Author

Hi, thanks for looking at this.
We use autoscaling for vlinsert and this is what we have in our env:
image

Meanwhile we are trying to mitigate this with a prestop sleep and short http.connTimeout on vlinsert to close clients keep-alive connections before the sleep ends.

@func25 func25 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for reporting this issue!

Comment thread app/vlstorage/netinsert/netinsert.go
…ad of the shutdown context

The final flush during graceful shutdown reused the already-canceled
shutdown context, so the last buffered data block failed instantly with
"context canceled" and was dropped. Send every data block with its own
timeout instead, consistent with -remoteWrite.sendTimeout in vlagent.

@cubic-dev-ai cubic-dev-ai Bot 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.

All reported issues were addressed across 5 files (changes from recent commits).

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment thread app/vlstorage/netinsert/netinsert.go
@func25

func25 commented Jul 9, 2026

Copy link
Copy Markdown
Member

*Note: after changing the original direction of this PR to sending timeout, it seems to also incidentally fix #1512. Assigned to owner of #1512.

@func25 func25 assigned cuongleqq and unassigned func25 Jul 9, 2026

@cubic-dev-ai cubic-dev-ai Bot 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.

All reported issues were addressed across 4 files (changes from recent commits).

Tip: Review your code locally with the cubic CLI to iterate faster.

Re-trigger cubic

Comment thread docs/victorialogs/CHANGELOG.md Outdated
# Conflicts:
#	docs/victorialogs/CHANGELOG.md
@cuongleqq

cuongleqq commented Jul 18, 2026

Copy link
Copy Markdown
Contributor

Thanks @github-vincent-miszczak! After an internal discussion, we settled on a configurable -insert.drainTimeout (default 5s) for the shutdown drain, along with the current sendTimeout. I pushed the change and also cleaned up the PR.

Signed-off-by: Cuong Le <cuongleqq@gmail.com>
Comment thread app/vlstorage/netinsert/netinsert.go
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.

3 participants