Fixed panic on stream create failure (with filestore)

This was introduced by the change for ipQueues in #2931.
The (*ipQueue).unregister() was written with a protection for
the ipQueue to be nil, however, mset.outq is actually not a bare
ipQueue but a jsOutQ that embeds a pointer to an ipQueue. So we
need to implement register() for jsOutQ.

Added a test that reproduced the issue, but found it with a flapping
test (TestJetStreamLongStreamNamesAndPubAck) that failed due to
a file name too long.

Signed-off-by: Ivan Kozlovic <ivan@synadia.com>
This commit is contained in:
Ivan Kozlovic
2022-03-22 15:21:01 -06:00
parent 9d6525c8a3
commit 8d4ff4bc96
2 changed files with 24 additions and 0 deletions

View File

@@ -16210,6 +16210,23 @@ func TestJetStreamRemoveExternalSource(t *testing.T) {
checkStreamMsgs(jsa, "queue", 20)
}
func TestJetStreamAddStreamWithFilestoreFailure(t *testing.T) {
s := RunBasicJetStreamServer()
if config := s.JetStreamConfig(); config != nil {
defer removeDir(t, config.StoreDir)
}
defer s.Shutdown()
// Cause failure to create stream with filestore.
// In one of ipQueue changes, this could cause a panic, so verify that we get
// a failure to create, but no panic.
if _, err := s.globalAccount().addStreamWithStore(
&StreamConfig{Name: "TEST"},
&FileStoreConfig{BlockSize: 2 * maxBlockSize}); err == nil {
t.Fatal("Expected failure, did not get one")
}
}
///////////////////////////////////////////////////////////////////////////
// Simple JetStream Benchmarks
///////////////////////////////////////////////////////////////////////////

View File

@@ -3174,6 +3174,13 @@ func (q *jsOutQ) send(msg *jsPubMsg) {
q.push(msg)
}
func (q *jsOutQ) unregister() {
if q == nil {
return
}
q.ipQueue.unregister()
}
// StoredMsg is for raw access to messages in a stream.
type StoredMsg struct {
Subject string `json:"subject"`