Skip to content

Commit

Permalink
fixed bug of the actor's Destroy method
Browse files Browse the repository at this point in the history
  • Loading branch information
dobyte committed Nov 1, 2024
1 parent 67fc06e commit 5aaa094
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
13 changes: 12 additions & 1 deletion cluster/node/actor.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,10 +135,19 @@ func (a *Actor) Push(uid int64, message *cluster.Message) {

// Destroy 销毁Actor
func (a *Actor) Destroy() {
if !a.state.CompareAndSwap(started, destroyed) {
if !a.destroy() {
return
}

a.scheduler.remove(a.Kind(), a.ID())
}

// 销毁Actor
func (a *Actor) destroy() bool {
if !a.state.CompareAndSwap(started, destroyed) {
return false
}

a.processor.Destroy()

a.scheduler.batchUnbindActor(func(relations map[int64]map[string]*Actor) {
Expand All @@ -154,6 +163,8 @@ func (a *Actor) Destroy() {
close(a.mailbox)

close(a.fnChan)

return true
}

// 绑定用户
Expand Down
4 changes: 1 addition & 3 deletions cluster/node/scheduler.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,7 @@ func (s *Scheduler) kill(kind, id string) bool {
return false
}

act.Destroy()

return true
return act.destroy()
}

// 移除Actor
Expand Down

0 comments on commit 5aaa094

Please sign in to comment.