Repository navigation
fix: reject fetch when the client SSE stream is on another replica - #187
Open
davidgrldo wants to merge 1 commit into
Open
davidgrldo wants to merge 1 commit into
davidgrldo wants to merge 1 commit into
Conversation
Fixes benc-uk#185 With multiple replicas and no sticky sessions, /api/fetch and the /updates SSE stream can land on different pods. handleFetchData then added the clientID to the namespace group even though the client has no SSE channel on this pod, leaving a phantom group member. Every informer event for that namespace sent to a nil channel and blocked the informer handler goroutine forever, so client-go's unbounded pending-notification buffer grew on every event and every 1 minute resync until the pod was OOMKilled (~450 MiB/hour, from ~200 MiB steady state to a 2 GiB limit in ~4 hours). - handleFetchData now only joins the namespace group when the clientID has an SSE connection on this pod, and returns 409 otherwise - The frontend retries the fetch (up to 5 times) on 409, so it lands on the pod holding the SSE stream - go.mod temporarily replaces go-rest-api with a fork carrying the broker fix (non-blocking sends, no goroutine leak, mutex-guarded state); drop the replace once the fix is released upstream - Helm values now document that multiple replicas need sticky sessions for live updates to work Note: the broker-side fix is required in addition to the guard, because a client disconnect (listen) can still race a send between the group cleanup and the channel delete.
This branch has not been deployed
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.
Fixes #185
Root cause
With multiple replicas and no sticky sessions,
/api/fetchand the/updatesSSE stream can land on different pods.handleFetchDatathen added theclientIDto the namespace group even though the client has no SSE channel on this pod, leaving a phantom group member. Every informer event for that namespace sent on a nil channel and blocked the informer handler goroutine forever, so client-go's unbounded pending-notification buffer grew on every event and every 1-minute resync until the pod was OOMKilled (~450 MiB/hour in the reporter's cluster).Changes
handleFetchDataonly joins the namespace group when theclientIDhas an SSE connection on this pod, and returns 409 otherwise — no more phantom group membersgo.modtemporarily replacesgo-rest-apiwith a fork (tagv1.1.1-fix.185) carrying the broker-side fix: non-blocking sends (skip missing clients, drop when the receiver is not ready),Streamexiting onr.Context().Done()(goroutine leak), and mutex-guarded broker state. See fix(sse): never block senders, and stop leaking stream goroutines go-rest-api#4 — thereplaceshould be dropped once that is released upstreamWhy both sides are needed
The guard alone still leaves a small window: a client disconnect (
listen()) can race a send between the group cleanup and the channel delete, which is enough to stall an informer once. The broker fix (benc-uk/go-rest-api#4) makes sends non-blocking, so a stall can never happen again; the guard + frontend retry restore correct behaviour (live updates) for the multi-replica case.Verification
go build ./...,go vet ./...,go test ./server/services/ -short✅make lintequivalents: eslint, prettier, golangci-lint — 0 issues ✅-race✅Workaround for existing users until this ships: run a single replica or enable sticky sessions on the ingress.