-
Notifications
You must be signed in to change notification settings - Fork 106
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix spawning actors with duplicate id bug #164
Conversation
@@ -223,7 +223,7 @@ func TestSpawn(t *testing.T) { | |||
wg.Wait() | |||
} | |||
|
|||
func TestSpawnDuplicateId(t *testing.T) { | |||
func TestSpawnDuplicateKind(t *testing.T) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
renamed this existing test case to be more accurate
If you check Registry, it's not possible to add 2 actors with same ID. An event is broadcasted and you can subscribe into that in case you want to have a specific logic. |
I understand that there is a DuplicateIdEvent that is published in this scenario, but the issue is that the startup sequence (actor.Initialized and actor.Started events) is still triggered for the duplicate actor. This can be seen in the issue I raised #163. In my opinion, this is unexpected behavior that can cause bugs. |
I will investigate it further and see what is causing the issue. Normally, the registry should not do anything when the process exists, thus no duplicate events should be present |
@troygilman0 @tprifti After some investigation I think we need to prevent func (e *Engine) SpawnProc(p Processer) *PID {
e.Registry.add(p)
// p.Start() remove this!
return p.PID()
} func (r *Registry) add(proc Processer) {
r.mu.Lock()
id := proc.PID().ID
if _, ok := r.lookup[id]; ok {
r.mu.Unlock()
r.engine.BroadcastEvent(ActorDuplicateIdEvent{PID: proc.PID()})
return
}
r.lookup[id] = proc
r.mu.Unlock()
proc.Start() // Add this
} |
Looks good to go. Thanks for all the effort. |
This PR addresses this issue #163.