fix(android): add polling fallback for session_started race condition
When multiple Android devices join a keygen session nearly simultaneously, the last joiner may miss the session_started gRPC event because it's sent before the device has fully set up its event subscription. This fix adds a 2-second delayed polling check after join to detect if the session has already started. If the session is in_progress and we haven't started keygen yet, trigger it via polling instead of relying solely on the session_started event. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
136a5ba851
commit
c3d5da46f7
|
|
@ -502,8 +502,25 @@ class MainViewModel @Inject constructor(
|
|||
if (joinResult.sessionStatus == "in_progress") {
|
||||
android.util.Log.d("MainViewModel", "Session already in_progress, triggering keygen immediately")
|
||||
startKeygenAsJoiner()
|
||||
} else {
|
||||
// Otherwise, wait for session_started event
|
||||
// But also poll session status after a delay in case we missed the event
|
||||
// This handles the race condition where session_started is sent before we're ready
|
||||
viewModelScope.launch {
|
||||
delay(2000) // Wait 2 seconds
|
||||
val joinInfo = pendingJoinKeygenInfo
|
||||
if (joinInfo != null && joinInfo.sessionId == sessionInfo.sessionId) {
|
||||
android.util.Log.d("MainViewModel", "Checking session status after delay...")
|
||||
val statusResult = repository.getSessionStatus(sessionInfo.sessionId)
|
||||
statusResult.onSuccess { status ->
|
||||
if (status.status == "in_progress" && pendingJoinKeygenInfo != null) {
|
||||
android.util.Log.d("MainViewModel", "Session is now in_progress (detected via polling), triggering keygen")
|
||||
startKeygenAsJoiner()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// Otherwise, wait for session_started event
|
||||
},
|
||||
onFailure = { e ->
|
||||
android.util.Log.e("MainViewModel", "gRPC join failed", e)
|
||||
|
|
|
|||
Loading…
Reference in New Issue