From 36b027db09ce608d4c9aaec7589b4c502c9796d9 Mon Sep 17 00:00:00 2001 From: Ivan Kozlovic Date: Tue, 18 Jan 2022 16:51:16 -0700 Subject: [PATCH] [FIXED] Log failure to create a channel If creation of a channel failed, this error was not always logged. Signed-off-by: Ivan Kozlovic --- server/server.go | 7 ++++++- server/server_storefailures_test.go | 20 ++++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/server/server.go b/server/server.go index 093dcaba..90c4aee3 100644 --- a/server/server.go +++ b/server/server.go @@ -312,7 +312,12 @@ func (cs *channelStore) createChannel(s *StanServer, name string) (*channel, err return c, err } -func (cs *channelStore) createChannelLocked(s *StanServer, name string, id uint64) (*channel, error) { +func (cs *channelStore) createChannelLocked(s *StanServer, name string, id uint64) (retChan *channel, retErr error) { + defer func() { + if retErr != nil { + cs.stan.log.Errorf("Creating channel %q failed: %v", name, retErr) + } + }() // It is possible that there were 2 concurrent calls to lookupOrCreateChannel // which first uses `channelStore.get()` and if not found, calls this function. // So we need to check now that we have the write lock that the channel has diff --git a/server/server_storefailures_test.go b/server/server_storefailures_test.go index e4926b6f..e903b180 100644 --- a/server/server_storefailures_test.go +++ b/server/server_storefailures_test.go @@ -736,3 +736,23 @@ func TestDeleteChannelStoreError(t *testing.T) { t.Fatalf("Timer should have been stopped") } } + +func TestCreateChannelError(t *testing.T) { + opts := GetDefaultOptions() + logger := &checkErrorLogger{checkErrorStr: "Creating channel \"foo\" failed: " + errOnPurpose.Error()} + opts.CustomLogger = logger + s := runServerWithOpts(t, opts, nil) + defer s.Shutdown() + + s.channels.Lock() + ms := &testChannelStoreFailStore{Store: s.channels.store} + s.channels.store = ms + s.channels.Unlock() + + if _, err := s.channels.createChannel(s, "foo"); err == nil { + t.Fatal("Expected error, got none") + } + if !logger.gotError { + t.Fatal("Did not log the expected error") + } +}