Skip to content

fix: move SetToServerProtocol outside write lock in getOrNewWorkloadPublisher [fj4WqyCCw3C5ShR1RfB7MoBPTpkRrBFYP1uT35g3MvT] - #15593

Open
waterWang wants to merge 2 commits into
linkerd:mainfrom
waterWang:fix/15583-move-settoserverprotocol-outside-writelock
Open

waterWang wants to merge 2 commits into
linkerd:mainfrom
waterWang:fix/15583-move-settoserverprotocol-outside-writelock

Conversation

@waterWang

Copy link
Copy Markdown

Move the expensive SetToServerProtocol() call (O(n_servers) label-matching) outside the WorkloadWatcher write lock.

Problem: getOrNewWorkloadPublisher() acquires ww.mu.Lock() and holds it across the entire function, including the cache-miss path where updatePod() calls SetToServerProtocol() - an O(n_servers) label-matching scan. During a thundering-herd Subscribe() storm, this write lock blocks all submitPodUpdate() readers (via RWMutex semantics), causing a self-reinforcing death spiral.

Fix: Move the pod lookup before the lock (read-only informer cache access), then only the publishers map access is inside the critical section. After releasing the lock, call updatePod() / updateExternalWorkload() outside the lock. Each publisher own wp.mu protects concurrent access.

Closes #15583

Signed-off-by: waterWang waterWang@users.noreply.github.com

…ublisher

Move the expensive SetToServerProtocol() call (O(n_servers) label-matching) outside the WorkloadWatcher write lock. The write lock is only needed to protect the publishers map access; the protocol detection can run after the lock is released.

During thundering-herd Subscribe() storms, holding the write lock across the full scan blocks all submitPodUpdate() readers (via RWMutex semantics), causing a death spiral where existing proxy streams stop receiving endpoint updates and time out, which triggers reconnections that add more writers.

Signed-off-by: waterWang <waterWang@users.noreply.github.com>
@raykroeker

Copy link
Copy Markdown
Member

@waterWang This no longer holds the write lock for the duration of SetToServerProtocol but does not address #15583.
It implements a potential work-around. Remove the assertion, fix the title and I can approve the change.

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.

Destination controller enters unrecoverable death spiral under mass Subscribe() — no backpressure or circuit breaker

2 participants