Skip to content

fix(channel): return ChannelMember by value from GetMember#645

Merged
FranDias merged 3 commits into
nex-crm:mainfrom
CharlieKerfoot:fix/getmember-returns-pointer
May 5, 2026
Merged

fix(channel): return ChannelMember by value from GetMember#645
FranDias merged 3 commits into
nex-crm:mainfrom
CharlieKerfoot:fix/getmember-returns-pointer

Conversation

@CharlieKerfoot
Copy link
Copy Markdown
Contributor

@CharlieKerfoot CharlieKerfoot commented May 5, 2026

Summary

GetMember in internal/channel/cursor.go:13 returned a pointer into s.members after releasing the RLock, so callers could read the struct while a writer holding s.mu mutated the same slice element. Pretty classic data race. The lock protected the lookup but not the dereference.

Fix

Return ChannelMember by value (and a zero value on miss) so the copy happens under the read lock. Callers that previously held the pointer now get a snapshot, which is what the lock semantics already implied.

Tests

bash scripts/test-go.sh with -race against internal/channel passes; the previous shape would trip the race detector under concurrent MarkRead + GetMember, the new shape doesn't since no aliasing escapes the lock.

Summary by CodeRabbit

  • Refactor
    • Internal adjustment to how channel membership data is returned and handled to streamline internal data access and reduce indirection.

Note: This release contains internal improvements with no user-facing changes.

@CharlieKerfoot CharlieKerfoot requested review from a team and FranDias as code owners May 5, 2026 00:40
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 5, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: a3db3e97-a099-4b08-91c6-1180505aba8e

📥 Commits

Reviewing files that changed from the base of the PR and between e7a27ea and 0733719.

📒 Files selected for processing (1)
  • internal/channel/cursor.go

📝 Walkthrough

Walkthrough

The GetMember method on Store now returns a ChannelMember value instead of a pointer; return paths were updated to return the matched value or an empty ChannelMember{} with a bool for success.

Changes

Return Type Refactor

Layer / File(s) Summary
Signature
internal/channel/cursor.go
GetMember signature changed from (*ChannelMember, bool) to (ChannelMember, bool).
Implementation
internal/channel/cursor.go
Return on match updated from &s.members[i], true to s.members[i], true; miss now returns ChannelMember{}, false.
Module Metadata
go.mod
Module file present in diff context (no code-level API change).

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Poem

I nibble code in twilight's gleam,
Values hop out, no pointers lean.
A member returned, whole and bright,
Simpler trails beneath moonlight. 🐇✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: returning ChannelMember by value instead of by pointer from the GetMember method.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

CharlieKerfoot and others added 2 commits May 5, 2026 09:29
The previous signature returned a pointer into s.members after releasing
the RLock, so callers could read the struct while a writer holding s.mu
mutated the same slice element. Returning by value forces the copy to
happen under the read lock, matching what the lock semantics already
implied.
@FranDias FranDias force-pushed the fix/getmember-returns-pointer branch from e7a27ea to 0733719 Compare May 5, 2026 13:40
@FranDias FranDias merged commit 6afad81 into nex-crm:main May 5, 2026
17 checks passed
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