Wait for guest user setup before firing authenticated API calls#1703
Wait for guest user setup before firing authenticated API calls#1703aleksandar-apostolov wants to merge 1 commit into
Conversation
PR checklist ✅All required conditions are satisfied:
🎉 Great job! This PR is ready for review. |
6b86dcd to
ba62c23
Compare
WalkthroughStreamVideoClient now synchronizes API calls with guest user setup. The ChangesGuest user setup synchronization in API calls
🎯 3 (Moderate) | ⏱️ ~20 minutes
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In
`@stream-video-android-core/src/main/kotlin/io/getstream/video/android/core/StreamVideoClient.kt`:
- Around line 294-296: The current use of runCatching around awaiting
guestUserJob swallows failures from setupGuestUser; change the guestUserJob
handling so failures propagate instead of being ignored—i.e., keep the existing
guard (guestUserJob?.takeIf { currentCoroutineContext()[Job] !== it }?.let { job
-> ... }) but replace runCatching { job.await() } with a direct await that will
throw on error (or explicitly rethrow the exception), so the guest-auth gate
behaves like connectAsync/Call.join and the apiCall cannot proceed with an
invalid/anonymous token when setupGuestUser fails.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: 42dfb45b-c8a7-47b9-ace9-372ac484a01e
📒 Files selected for processing (2)
stream-video-android-core/src/main/kotlin/io/getstream/video/android/core/StreamVideoClient.ktstream-video-android-core/src/test/kotlin/io/getstream/video/android/core/StreamVideoClientTest.kt
SDK Size Comparison 📏
|
… device registration Guest user setup runs asynchronously: StreamVideoBuilder.build returns immediately while setupGuestUser kicks off a background createGuest call to fetch the JWT. Any authenticated request that fires in that window goes out with stream-auth-type "anonymous" and no Authorization header, so the backend silently registers it against the wrong identity. The customer-visible effect is push device registration succeeding under !anon and incoming-call pushes never reaching the guest user. apiCall now awaits guestUserJob before invoking the request block, with a self-job guard so createGuestUser — which also goes through apiCall — does not await its own enclosing job and deadlock. Adds two regression tests: one for the wait, one for the deadlock guard. AND-1202
ba62c23 to
f13c6a4
Compare
|



Goal
Closes AND-1202 — push notifications never arrived for guest users on Android.
StreamVideoBuilder.build()returns immediately whilesetupGuestUserruns in the background. Ifclient.createDevice(pushDevice)(or any other authenticated API call) fires before that completes, the request goes out with noAuthorizationheader andstream-auth-type: anonymous, so the backend silently registers it against!anoninstead of the guest's identity. iOS doesn't hit this because integrators typically callsetDevicefrom the PushKit callback, afterconnectTaskhas finished. RN doesn't hit it because device registration reads_useronly afterconnectUser(response.user, ...).Implementation
apiCallnow awaitsguestUserJobbefore invoking the request block.currentCoroutineContext()[Job] !== job) skips the await whencreateGuestUseris itself running insideguestUserJob, so it doesn't await its own enclosingDeferredand deadlock.Testing
StreamVideoClientTest:apiCall waits for guestUserJob to complete before invoking the blockapiCall does not deadlock when invoked from within guestUserJob