Skip to content
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 send nil pid #124

Merged
merged 2 commits into from
Dec 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion actor/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ type Engine struct {
address string
remote Remoter
eventStream *PID
initErrors []error
}

type EngineOpts struct {
Expand Down Expand Up @@ -126,6 +125,13 @@ func (e *Engine) BroadcastEvent(msg any) {
}

func (e *Engine) send(pid *PID, msg any, sender *PID) {
// TODO: We might want to log something here. Not yet decided
// what could make sense. Send to dead letter or as event?
// Dead letter would make sense cause the destination is not
// reachable.
if pid == nil {
return
}
if e.isLocalMessage(pid) {
e.SendLocal(pid, msg, sender)
return
Expand Down Expand Up @@ -255,6 +261,9 @@ func (e *Engine) Unsubscribe(pid *PID) {
}

func (e *Engine) isLocalMessage(pid *PID) bool {
if pid == nil {
return false
}
return e.address == pid.Address
}

Expand Down
5 changes: 5 additions & 0 deletions actor/engine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ func newTickReceiver(wg *sync.WaitGroup) Producer {
}
}

func TestSendToNilPID(t *testing.T) {
e, _ := NewEngine(nil)
e.Send(nil, "foo")
}

func TestSendRepeat(t *testing.T) {
var (
wg = &sync.WaitGroup{}
Expand Down