Skip to content

fix: Prevent race between provisionerd connect and close #6206

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Feb 14, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
fix: Prevent race between provisionerd connect and close
  • Loading branch information
mafredri committed Feb 14, 2023
commit e76b59e8635f18e1a50694a7e42aac4e8d8a58ad
13 changes: 12 additions & 1 deletion provisionerd/provisionerd.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,17 @@ func (p *Server) connect(ctx context.Context) {
p.opts.Logger.Warn(context.Background(), "failed to dial", slog.Error(err))
continue
}
// Ensure connection is not left hanging during a race between
// close and dial succeeding.
p.mutex.Lock()
if p.isClosed() {
client.DRPCConn().Close()
p.mutex.Unlock()
break
}
p.clientValue.Store(client)
p.mutex.Unlock()

p.opts.Logger.Debug(context.Background(), "connected")
break
}
Expand Down Expand Up @@ -390,7 +400,8 @@ func retryable(err error) bool {
// is not retryable() or the context expires.
func (p *Server) clientDoWithRetries(
ctx context.Context, f func(context.Context, proto.DRPCProvisionerDaemonClient) (any, error)) (
any, error) {
any, error,
) {
for retrier := retry.New(25*time.Millisecond, 5*time.Second); retrier.Wait(ctx); {
client, ok := p.client()
if !ok {
Expand Down