Skip to content

Comments

[FIXED] Panic after hash check and concurrent compact#7697

Merged
neilalexander merged 1 commit intomainfrom
maurice/cache-nil-panic
Jan 5, 2026
Merged

[FIXED] Panic after hash check and concurrent compact#7697
neilalexander merged 1 commit intomainfrom
maurice/cache-nil-panic

Conversation

@MauriceVanVeen
Copy link
Member

In rare edge cases the server could panic here:

	if !hashChecked {
		mb.cache.idx[seq-mb.cache.fseq] = (bi | cbit) // <----
	}
[WRN] Catchup for stream '$G > test-stream' resetting first sequence: 1064 on catchup request
...
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0xb7071d]

goroutine 91 [running]:
github.com/nats-io/nats-server/v2/server.(*msgBlock).cacheLookupEx(0xc0003ca000, 0x42c, 0xc000c42890, 0x1)
	server/filestore.go:7924 +0xfdd

This was likely due to the defer smb.finishedWithCache() which sets mb.cache = nil without holding the lock if a fs.compact ran concurrently while the hash needed to be checked when looking up a message for that same block.

Signed-off-by: Maurice van Veen github@mauricevanveen.com

Signed-off-by: Maurice van Veen <github@mauricevanveen.com>
@MauriceVanVeen MauriceVanVeen requested a review from a team as a code owner January 5, 2026 10:08
Copy link
Member

@neilalexander neilalexander left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@neilalexander neilalexander merged commit 41ec024 into main Jan 5, 2026
130 of 136 checks passed
@neilalexander neilalexander deleted the maurice/cache-nil-panic branch January 5, 2026 11:44
neilalexander added a commit that referenced this pull request Jan 6, 2026
Includes the following:

- #7658
- #7659
- #7661
- #7662
- #7663
- #7642
- #7668
- #7683
- #7685
- #7686
- #7678
- #7691
- #7696
- #7697
- #7698
- #7699
- #7700

Signed-off-by: Neil Twigg <neil@nats.io>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants