@@ -262,6 +262,8 @@ type manager struct {
262262 // processed.
263263 chainCreatorShutdownCh chan struct {}
264264 chainCreatorExited sync.WaitGroup
265+ context context.Context
266+ cancelContext context.CancelFunc
265267
266268 chainsLock sync.Mutex
267269 // Key: Chain's ID
@@ -324,7 +326,11 @@ func New(config *ManagerConfig) (Manager, error) {
324326 return nil , err
325327 }
326328
329+ context , cancelContext := context .WithCancel (context .Background ())
330+
327331 return & manager {
332+ context : context ,
333+ cancelContext : cancelContext ,
328334 Aliaser : ids .NewAliaser (),
329335 ManagerConfig : * config ,
330336 chains : make (map [ids.ID ]handler.Handler ),
@@ -468,7 +474,7 @@ func (m *manager) createChain(chainParams ChainParameters) {
468474
469475 // Tell the chain to start processing messages.
470476 // If the X, P, or C Chain panics, do not attempt to recover
471- chain .Handler .Start (context . TODO () , ! m .CriticalChains .Contains (chainParams .ID ))
477+ chain .Handler .Start (m . context , ! m .CriticalChains .Contains (chainParams .ID ))
472478}
473479
474480// Create a chain
@@ -1523,6 +1529,7 @@ func (m *manager) Shutdown() {
15231529 m .Log .Info ("shutting down chain manager" )
15241530 m .chainsQueue .Close ()
15251531 close (m .chainCreatorShutdownCh )
1532+ m .cancelContext ()
15261533 m .chainCreatorExited .Wait ()
15271534 m .ManagerConfig .Router .Shutdown (context .TODO ())
15281535}
0 commit comments