Skip to content

Commit

Permalink
Fix P-chain Shutdown deadlock (#2686)
Browse files Browse the repository at this point in the history
  • Loading branch information
StephenButtolph authored Jan 31, 2024
1 parent 4457903 commit e4fa404
Showing 1 changed file with 3 additions and 11 deletions.
14 changes: 3 additions & 11 deletions vms/platformvm/vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"fmt"
"math"
"net/http"
"sync"
"time"

"github.com/gorilla/rpc/v2"
Expand Down Expand Up @@ -95,7 +94,6 @@ type VM struct {
onShutdownCtx context.Context
// Call [onShutdownCtxCancel] to cancel [onShutdownCtx] during Shutdown()
onShutdownCtxCancel context.CancelFunc
awaitShutdown sync.WaitGroup

// TODO: Remove after v1.11.x is activated
pruned utils.Atomic[bool]
Expand Down Expand Up @@ -221,13 +219,9 @@ func (vm *VM) Initialize(
}

vm.onShutdownCtx, vm.onShutdownCtxCancel = context.WithCancel(context.Background())
vm.awaitShutdown.Add(1)
go func() {
defer vm.awaitShutdown.Done()

// Invariant: Gossip must never grab the context lock.
vm.Network.Gossip(vm.onShutdownCtx)
}()
// TODO: Wait for this goroutine to exit during Shutdown once the platformvm
// has better control of the context lock.
go vm.Network.Gossip(vm.onShutdownCtx)

vm.Builder = blockbuilder.New(
mempool,
Expand Down Expand Up @@ -431,8 +425,6 @@ func (vm *VM) Shutdown(context.Context) error {
}

vm.onShutdownCtxCancel()
vm.awaitShutdown.Wait()

vm.Builder.ShutdownBlockTimer()

if vm.bootstrapped.Get() {
Expand Down

0 comments on commit e4fa404

Please sign in to comment.