Skip to content

Commit

Permalink
x/ref/runtime/internal/rpc: fix proxymgr shutdown race (#410)
Browse files Browse the repository at this point in the history
Ensure that the proxymanager's monitoring goroutine terminates before the proxymanager itself terminates. This avoids a race between the monitoring goroutine issuing new RPCs to the mounttable and the runtime being shutdown. This fixes #409.
  • Loading branch information
cosnicolaou committed Jan 3, 2024
1 parent 3dce6c1 commit 0ef7ede
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions x/ref/runtime/internal/rpc/proxymgr.go
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,8 @@ func drainNotifyChan(ch chan struct{}) {
}
}

func (pm *proxyManager) watchForChanges(ctx *context.T, ch chan struct{}) {
func (pm *proxyManager) watchForChanges(ctx *context.T, ch, doneCh chan struct{}) {
defer close(doneCh)
for {
select {
case <-ctx.Done():
Expand All @@ -260,12 +261,17 @@ func (pm *proxyManager) watchForChanges(ctx *context.T, ch chan struct{}) {

func (pm *proxyManager) manageProxyConnections(ctx *context.T) {
notifyCh := make(chan struct{}, 10)
doneCh := make(chan struct{})

defer func() {
<-doneCh
}()
pm.updateAvailableProxies(ctx)
// Watch for changes in the set of available proxies so that for the
// 'all' policy, the server will connect to new proxies as they appear.
// For other policies reconnection may be little faster since the
// new set of proxies is already available.
go pm.watchForChanges(ctx, notifyCh)
go pm.watchForChanges(ctx, notifyCh, doneCh)

for {
select {
Expand Down

0 comments on commit 0ef7ede

Please sign in to comment.