Skip to content

Commit 7f9d0e9

Browse files
committed
ccl/sqlproxyccl: fixes a data race in the ACL's watcher
Fixes cockroachdb#108156. Regression from cockroachdb#108097. Previously, we updated the code to return w.controllers after releasing the lock because checkConnection may be long running, and we did not want to block new connections. We had forgotten the contract where fields on the Watcher object needs `mu` as they may be updated, so that approach had data races. This commit address that by ensuring that a copy of w.controllers is returned instead. Release note: None Epic: none
1 parent c5c821a commit 7f9d0e9

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

pkg/ccl/sqlproxyccl/acl/watcher.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,9 @@ func (w *Watcher) ListenForDenied(
276276

277277
w.listeners.ReplaceOrInsert(l)
278278

279-
return l, w.controllers
279+
// We need a new copy of w.controllers so that it doesn't race with the
280+
// add and update operations.
281+
return l, append([]AccessController(nil), w.controllers...)
280282
}()
281283
if err := checkConnection(ctx, connection, controllers); err != nil {
282284
w.removeListener(lst)

0 commit comments

Comments
 (0)