mirror of
https://github.com/gogrlx/nats-server.git
synced 2026-04-02 03:38:42 -07:00
Fix sid for split messages
When message is split we need to copy message arguments to avoid rewriting them with new message. Subject, reply and size were correctly copied by sid wasn't. That led to dropping some messages in clustered mode if they were split, and the second part was long enough to overwrite sid in the original buffer.
This commit is contained in:
@@ -341,3 +341,31 @@ func TestSplitDanglingArgBuf(t *testing.T) {
|
||||
t.Fatalf("Expected c.argBuf to be nil: %q\n", c.argBuf)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSplitMsgArg(t *testing.T) {
|
||||
_, c, _ := setupClient()
|
||||
|
||||
b := make([]byte, 1024)
|
||||
|
||||
copy(b, []byte("MSG hello.world RSID:14:8 6040\r\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"))
|
||||
c.parse(b)
|
||||
|
||||
copy(b, []byte("BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB\r\n"))
|
||||
c.parse(b)
|
||||
|
||||
wantSubject := "hello.world"
|
||||
wantSid := "RSID:14:8"
|
||||
wantSzb := "6040"
|
||||
|
||||
if string(c.pa.subject) != wantSubject {
|
||||
t.Fatalf("Incorrect subject: want %q, got %q", wantSubject, c.pa.subject)
|
||||
}
|
||||
|
||||
if string(c.pa.sid) != wantSid {
|
||||
t.Fatalf("Incorrect sid: want %q, got %q", wantSid, c.pa.sid)
|
||||
}
|
||||
|
||||
if string(c.pa.szb) != wantSzb {
|
||||
t.Fatalf("Incorrect szb: want %q, got %q", wantSzb, c.pa.szb)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user