From c3431635c8f952a9ac2b7301d191e872fef20ce3 Mon Sep 17 00:00:00 2001 From: AJ Roetker Date: Tue, 29 Jun 2021 16:16:49 -0700 Subject: [PATCH] Avoid panics on not owner errors because they should go away (#169) * Avoid panics on not owner errors because they should go away * Apply suggestions from code review Co-authored-by: Eric Sniff Co-authored-by: Eric Sniff --- mailbox.go | 6 +++++- server.go | 5 ++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/mailbox.go b/mailbox.go index cad01a7..bf1f6ca 100644 --- a/mailbox.go +++ b/mailbox.go @@ -8,6 +8,7 @@ import ( "sync" "time" + "github.com/lytics/grid/v3/registry" "github.com/lytics/retry" ) @@ -164,7 +165,10 @@ func newMailbox(s *Server, name, nsName string, size int) (*Mailbox, error) { cancel() return err != nil }) - if err != nil { + // Ingnore ErrNotOwner because most likely the previous owner panic'ed or exited badly. + // So we'll ignore the error and let the mailbox creator retry later. We don't want to panic + // in that case because it will take down more mailboxes and make it worse. + if err != nil && err != registry.ErrNotOwner { panic(fmt.Errorf("%w: unable to deregister mailbox: %v, error: %v", errDeregisteredFailed, nsName, err)) } } diff --git a/server.go b/server.go index 970417d..0d8cf55 100644 --- a/server.go +++ b/server.go @@ -470,7 +470,10 @@ func (s *Server) deregisterActor(nsName string) { cancel() return err != nil }) - if err != nil { + // Ingnore ErrNotOwner because most likely the previous owner panic'ed or exited badly. + // So we'll ignore the error and let the mailbox creator retry later. We don't want to panic + // in that case because it will take down more mailboxes and make it worse. + if err != nil && err != registry.ErrNotOwner { panic(fmt.Sprintf("unable to deregister actor: %v, error: %v", nsName, err)) } }