Skip to content

Commit

Permalink
Merge pull request #1232 from nats-io/report_err_on_chan_create_failure
Browse files Browse the repository at this point in the history
[FIXED] Log failure to create a channel
  • Loading branch information
kozlovic authored Jan 19, 2022
2 parents 367e841 + 36b027d commit 6f31e06
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
7 changes: 6 additions & 1 deletion server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,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
Expand Down
20 changes: 20 additions & 0 deletions server/server_storefailures_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
}

0 comments on commit 6f31e06

Please sign in to comment.