Skip to content

Commit

Permalink
go/runtime/host/sandbox: Fix possible data race
Browse files Browse the repository at this point in the history
The data race existed because the cancel function that is referenced inside a
goroutine waiting for initialization to complete was unintentionally
overwritten.
  • Loading branch information
kostko committed Jun 17, 2020
1 parent 18471ae commit 2046573
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changelog/3024.bugfix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
go/runtime/host/sandbox: Fix possible data race

The data race existed because the cancel function that is referenced inside a
goroutine waiting for initialization to complete was unintentionally
overwritten.
8 changes: 4 additions & 4 deletions go/runtime/host/sandbox/sandbox.go
Original file line number Diff line number Diff line change
Expand Up @@ -315,15 +315,15 @@ func (r *sandboxedRuntime) startProcess() (err error) {

// Perform common host initialization.
var rtVersion *version.Version
initCtx, cancel := context.WithTimeout(ctx, runtimeInitTimeout)
defer cancel()
initCtx, cancelInit := context.WithTimeout(ctx, runtimeInitTimeout)
defer cancelInit()
if rtVersion, err = pc.InitHost(initCtx, conn); err != nil {
return fmt.Errorf("failed to initialize connection: %w", err)
}

// Perform configuration-specific host initialization.
exInitCtx, cancel := context.WithTimeout(ctx, runtimeExtendedInitTimeout)
defer cancel()
exInitCtx, cancelExInit := context.WithTimeout(ctx, runtimeExtendedInitTimeout)
defer cancelExInit()
ev, err := r.cfg.HostInitializer(exInitCtx, r, *rtVersion, p, pc)
if err != nil {
return fmt.Errorf("failed to initialize connection: %w", err)
Expand Down

0 comments on commit 2046573

Please sign in to comment.