Skip to content

Commit

Permalink
fix incorrect gen.ProcessOptions.Context handling
Browse files Browse the repository at this point in the history
  • Loading branch information
halturin committed Jun 30, 2022
1 parent cb9008d commit d9bfaba
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions node/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit d9bfaba

Please sign in to comment.