fix invalid memory address or nil pointer dereference#10
Conversation
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>
jesusvazquez
left a comment
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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>
|
Similar to #7 (comment) the CI seems very flaky 😥
|
**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>
#### 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>
This is the fixup for changes in hashicorp#325
The
net.Connmust be captured in thedeferinside thehandleConn, so the shadowed variable didn't cause panic, when the error happens inside theRemoveLabelHeaderFromStream.Note, I will open a PR to fix this upstream later.
Relates to grafana/mimir#13287