Commit 2c47695
fix(realtime): resolve additional bugs in auth token handling and unsubscribe flow
This commit addresses additional bugs discovered during code review:
**Auth Token Handling Bug:**
1. **setAuth() Token Assignment**
- Fixed critical bug where wrong variable was assigned to accessToken
- Was using input parameter `token` instead of computed `tokenToSend`
- This prevented access token callback from being properly stored
- Now correctly uses `tokenToSend` which includes callback result
2. **setAuth() Channel Updates**
- Fixed sending wrong token to channels during auth updates
- Was sending `token` parameter instead of `tokenToSend`
- Channels now receive the correct token from callback
**Disconnect Cleanup:**
3. **Missing reconnectTask Cancellation**
- disconnect() now properly cancels reconnectTask
- Prevents reconnect attempts during explicit disconnect
**Subscription Improvements:**
4. **Socket Health Check During Retry**
- Added socket connection verification after retry delay
- Prevents subscription attempts on disconnected socket
- Aborts retry loop if socket disconnects during backoff
5. **Unsubscribe Confirmation**
- unsubscribe() now waits for server acknowledgment
- Ensures clean channel removal before returning
- Matches subscribe() behavior of waiting for status change
**Impact:**
- Fixes auth token not being updated when using callback
- Prevents sending stale/incorrect tokens to channels
- Cleaner disconnect and unsubscribe flows
- More robust subscription retry logic
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <[email protected]>1 parent 376a8fc commit 2c47695
File tree
2 files changed
+15
-3
lines changed- Sources/Realtime
2 files changed
+15
-3
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
138 | 138 | | |
139 | 139 | | |
140 | 140 | | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
141 | 149 | | |
142 | 150 | | |
143 | 151 | | |
| |||
240 | 248 | | |
241 | 249 | | |
242 | 250 | | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
243 | 254 | | |
244 | 255 | | |
245 | 256 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
519 | 519 | | |
520 | 520 | | |
521 | 521 | | |
| 522 | + | |
522 | 523 | | |
523 | 524 | | |
524 | 525 | | |
| |||
544 | 545 | | |
545 | 546 | | |
546 | 547 | | |
547 | | - | |
548 | | - | |
| 548 | + | |
| 549 | + | |
549 | 550 | | |
550 | 551 | | |
551 | 552 | | |
552 | 553 | | |
553 | 554 | | |
554 | 555 | | |
555 | 556 | | |
556 | | - | |
| 557 | + | |
557 | 558 | | |
558 | 559 | | |
559 | 560 | | |
| |||
0 commit comments