Skip to content

fix(flagd-proxy): guard cleanup against a multiplexer whose watcher has not started - #4

Open
arena-ai-coding-agent[bot] wants to merge 1 commit into
mainfrom
fix/proxy-cleanup-nil-cancel
Open

fix(flagd-proxy): guard cleanup against a multiplexer whose watcher has not started#4
arena-ai-coding-agent[bot] wants to merge 1 commit into
mainfrom
fix/proxy-cleanup-nil-cancel

Conversation

@arena-ai-coding-agent

Copy link
Copy Markdown

This PR

Fixes a nil-pointer panic found while reviewing flagd-proxy/pkg/service/subscriptions/manager.go.

The coordinator's cleanup loop cancels multiplexers with zero active subscriptions by invoking their cancelFunc. cancelFunc is only assigned by the watchResource goroutine, so a subscription that is registered and then cancelled before watchResource runs leaves a multiplexer in the map with an empty subs map and a nil cancelFunc. The next cleanup tick (every 5s) then called the nil function → panic → the whole flagd-proxy process crashes.

This is a startup-window race: a client that connects and disconnects quickly (e.g. a provider retrying before the CR/source exists, or a flapping client) while the watcher goroutine has not been scheduled yet.

Changes

  • flagd-proxy/pkg/service/subscriptions/manager.go
    • Extracted the cleanup body into cleanupOnce().
    • When a multiplexer with zero subscriptions has no cancelFunc yet, remove the dead entry directly instead of calling a nil function (the watcher goroutine, when it eventually runs, finds no multiplexer and exits).
  • flagd-proxy/pkg/service/subscriptions/manager_test.go
    • New regression test: Test_cleanupOnce_multiplexerWithoutStartedWatcher drives cleanupOnce() against a multiplexer whose watcher never started and asserts no panic and removal of the entry.

Related Issues

Related to the subscription-lifecycle work in open-feature#2030/open-feature#2031 (this is a distinct panic path in the same component).

How to test

cd flagd-proxy && go test -race ./pkg/service/subscriptions/...

Signed-off-by: Agi-Asi 206806952+Agi-Asi@users.noreply.github.com

…as not started

The coordinator's cleanup loop cancels multiplexers with zero active
subscriptions by invoking their cancelFunc. cancelFunc is only assigned
by the watchResource goroutine, so a subscription that is registered and
cancelled before watchResource runs leaves a multiplexer in the map with
empty subs and a nil cancelFunc. The next cleanup tick then called the
nil function and panicked, crashing flagd-proxy.

Refactor the cleanup body into cleanupOnce and handle the nil case by
removing the dead entry directly instead of calling a nil cancelFunc.
Adds a regression test for a multiplexer whose watcher never started.

Signed-off-by: Agi-Asi <206806952+Agi-Asi@users.noreply.github.com>

Co-authored-by: arena-agent <297053741+arena-agent@users.noreply.github.com>
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