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

[FIXED] Log failure to create a channel #1232

Merged
merged 1 commit into from
Jan 19, 2022
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
7 changes: 6 additions & 1 deletion server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
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")
}
}