diff --git a/node/core.go b/node/core.go index aeb57011..239ae934 100644 --- a/node/core.go +++ b/node/core.go @@ -279,17 +279,14 @@ func (c *core) deleteAlias(owner *process, alias etf.Alias) error { func (c *core) newProcess(name string, behavior gen.ProcessBehavior, opts processOptions) (*process, error) { - var processContext context.Context - var kill context.CancelFunc - mailboxSize := DefaultProcessMailboxSize if opts.MailboxSize > 0 { mailboxSize = int(opts.MailboxSize) } - processContext, kill = context.WithCancel(c.ctx) + processContext, kill := context.WithCancel(c.ctx) if opts.Context != nil { - processContext = context.WithValue(processContext, "context", processContext) + processContext, _ = context.WithCancel(opts.Context) } pid := c.newPID() @@ -352,7 +349,7 @@ func (c *core) newProcess(name string, behavior gen.ProcessBehavior, opts proces } // let the process decide whether to stop itself, otherwise its going to be killed - if !process.trapExit { + if process.trapExit == false { process.kill() } return nil @@ -363,6 +360,7 @@ func (c *core) newProcess(name string, behavior gen.ProcessBehavior, opts proces c.mutexNames.Lock() if _, exist := c.names[name]; exist { c.mutexNames.Unlock() + process.kill() // cancel context return nil, ErrTaken } c.names[name] = process.self @@ -450,7 +448,7 @@ func (c *core) spawn(name string, opts processOptions, behavior gen.ProcessBehav c.deleteProcess(process.self) // invoke cancel context to prevent memory leaks // and propagate context canelation - process.Kill() + process.kill() // notify all the linked process and monitors c.handleTerminated(process.self, name, reason) // make the rest empty