Skip to content

[Minor fixes] correct version comparison, nil-safe speaker update, and RLock/RUnlock mismatch#898

Open
siddimore wants to merge 1 commit intolivekit:mainfrom
siddimore:minor-fixes
Open

[Minor fixes] correct version comparison, nil-safe speaker update, and RLock/RUnlock mismatch#898
siddimore wants to merge 1 commit intolivekit:mainfrom
siddimore:minor-fixes

Conversation

@siddimore
Copy link
Copy Markdown

Why

Three independent issues found during a code walk through:

  • compareVersions produced wrong results for double-digit version components — the > branch used string comparison ("10" > "9" is false lexicographically) even though the < branch already used the correctly parsed integers.
  • OnSpeakersChanged used reflect to detect a nil participant — assigning a *RemoteParticipant directly into a Participant interface before checking nil creates a non-nil interface wrapping a nil pointer, so a plain == nil check silently fails. Using reflect is both unusual and unnecessary here.
  • getPublication held a write lock for a read-only operation — the lock acquisition was changed to RLock but defer p.lock.Unlock() was left behind, which would panic at runtime with a mismatched unlock.

What changed

File Change
utils.go Use parsed integer p1 > p2 instead of string parts1[i] > parts2[i]
room.go Check *RemoteParticipant nil before boxing into interface; remove reflect import
participant.go Fix defer p.lock.Unlock() → defer p.lock.RUnlock() to match the RLock
utils_test.go New table-driven tests for compareVersions, including the double-digit regression case

How tested

  • Added TestCompareVersions in utils_test.go covering equal, greater, less, double-digit components ("10.0.0" vs "9.0.0"), and differing length versions — all pass.
  • The room.go and participant.go changes are mechanical and covered by existing room/participant tests.

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.

1 participant