Skip to content

fix invalid memory address or nil pointer dereference#10

Merged
narqo merged 2 commits intomasterfrom
vldmr/panic-conn-handling
Nov 24, 2025
Merged

fix invalid memory address or nil pointer dereference#10
narqo merged 2 commits intomasterfrom
vldmr/panic-conn-handling

Conversation

@narqo
Copy link

@narqo narqo commented Nov 24, 2025

This is the fixup for changes in hashicorp#325

The net.Conn must be captured in the defer inside the handleConn, so the shadowed variable didn't cause panic, when the error happens inside the RemoveLabelHeaderFromStream.

Note, I will open a PR to fix this upstream later.

Relates to grafana/mimir#13287

The net.Conn must be captured in the defer, so the shadowed variable
didn't cause the panic, when the error happens in
RemoveLabelHeaderFromStream.

Signed-off-by: Vladimir Varankin <vladimir.varankin@grafana.com>
Copy link

@jesusvazquez jesusvazquez left a comment

Choose a reason for hiding this comment

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

Would it make sense to rename the conn below?

conn, streamLabel, err = RemoveLabelHeaderFromStream(conn)

net.go Outdated
// handleConn handles a single incoming stream connection from the transport.
func (m *Memberlist) handleConn(conn net.Conn) {
defer func() {
defer func(conn net.Conn) {
Copy link

@pracucci pracucci Nov 24, 2025

Choose a reason for hiding this comment

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

This is safe because the wrapped net.Conn returned by RemoveLabelHeaderFromStream() doesn't override the Close() but if in the future it will do it (unlikely honestly), then this change will trigger a latent bug. Maybe you can save a reference to the original connection instead, and close the wrapped if != nil and fallback to the original one?

Copy link
Author

Choose a reason for hiding this comment

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

I see the concern. I think the added test would catch this scenario. But I've also addressed it in e2d1a17 — I think it's simpler, and easier to follow like that.

Signed-off-by: Vladimir Varankin <vladimir.varankin@grafana.com>
@narqo
Copy link
Author

narqo commented Nov 24, 2025

Similar to #7 (comment) the CI seems very flaky 😥

[..] It fails on unrelated stuff.

Copy link

@pracucci pracucci left a comment

Choose a reason for hiding this comment

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

Thanks!

@narqo narqo merged commit 7fbd6a1 into master Nov 24, 2025
11 of 13 checks passed
narqo added a commit to grafana/dskit that referenced this pull request Nov 24, 2025
**What this PR does**:

The PR updates our member fork to bring changes
grafana/memberlist#10

>  fix invalid memory address or nil pointer dereference

**Which issue(s) this PR fixes**:

Relates to grafana/mimir#13287

Signed-off-by: Vladimir Varankin <vladimir.varankin@grafana.com>
narqo added a commit to grafana/mimir that referenced this pull request Nov 24, 2025
#### What this PR does

The PR updates our member fork to bring changes
grafana/memberlist#10

#### Which issue(s) this PR fixes or relates to

Closes #13287

#### Checklist

- [ ] Tests updated.
- [ ] Documentation added.
- [x] `CHANGELOG.md` updated - the order of entries should be
`[CHANGE]`, `[FEATURE]`, `[ENHANCEMENT]`, `[BUGFIX]`. If changelog entry
is not needed, please add the `changelog-not-needed` label to the PR.
- [ ]
[`about-versioning.md`](https://github.com/grafana/mimir/blob/main/docs/sources/mimir/configure/about-versioning.md)
updated with experimental features.

---------

Signed-off-by: Vladimir Varankin <vladimir.varankin@grafana.com>
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.

3 participants