Commit 25fd158
committed
Fixed setTrackEnabled orphaning track resources when cancelled before publish completes
A cancellation landing in startForegroundService or publishVideoTrack
unwound out of setTrackEnabled without any cleanup, abandoning the newly
created screencast track and, when the bind had already succeeded,
leaving ScreenCaptureService bound for the lifetime of the context. Each
enable path tears the unpublished track down in a finally block, so
cancellation and publish failures release capture, track resources, and
the service binding, and invoke the onStop callback exactly once, even
when the platform ended the projection while publishing was in flight.
A projection stop already dispatched on its callback thread can reach
the track after that cleanup disposed it, where ScreenCapturerAndroid
throws from stopCapture. LocalScreencastVideoTrack.stop() tolerates
losing that race instead of crashing the callback thread.
publishTrackImpl negotiates the sender transceiver concurrently with the
add track request, so a failed or cancelled request could leave a
negotiated transceiver holding its sender and SDP m-section with no
publication to unpublish. The rollback targets exactly the sender this
attempt created on the transport that created it, so it cannot detach a
concurrent publish of the same track, and the handle is recorded
non-cancellably so a cancellation cannot discard the RTC-thread result.
Sender handles retain the signal session state that owned their
transceiver. Aborting pending publishes and starting a reconnect replace
that state before cleanup can run, so a delayed continuation cannot
mutate the same publisher after a soft reconnect. The final eligibility
check runs on the RTC thread immediately before mutation. Stopping the
transceiver and releasing its m-section is reserved for video, matching
unpublishTrack.
LocalScreencastVideoTrack also never released its SurfaceTextureHelper,
so its capture thread outlived dispose() even on the normal teardown
path. The helper is registered with the track's CloseableManager,
matching LocalVideoTrack.
Fixes #9851 parent 500fd85 commit 25fd158
7 files changed
Lines changed: 593 additions & 91 deletions
File tree
- .changeset
- livekit-android-sdk/src/main/java/io/livekit/android/room
- participant
- track
- livekit-android-test/src
- main/java/io/livekit/android/test/mock
- test/java/io/livekit/android/room/participant
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
Lines changed: 69 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
133 | 133 | | |
134 | 134 | | |
135 | 135 | | |
| 136 | + | |
136 | 137 | | |
137 | 138 | | |
138 | 139 | | |
| |||
158 | 159 | | |
159 | 160 | | |
160 | 161 | | |
| 162 | + | |
| 163 | + | |
161 | 164 | | |
162 | 165 | | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
163 | 173 | | |
164 | 174 | | |
165 | 175 | | |
| |||
424 | 434 | | |
425 | 435 | | |
426 | 436 | | |
427 | | - | |
428 | | - | |
| 437 | + | |
| 438 | + | |
| 439 | + | |
| 440 | + | |
429 | 441 | | |
430 | | - | |
| 442 | + | |
| 443 | + | |
431 | 444 | | |
432 | 445 | | |
433 | 446 | | |
| |||
505 | 518 | | |
506 | 519 | | |
507 | 520 | | |
| 521 | + | |
| 522 | + | |
| 523 | + | |
508 | 524 | | |
509 | 525 | | |
510 | 526 | | |
| |||
535 | 551 | | |
536 | 552 | | |
537 | 553 | | |
| 554 | + | |
538 | 555 | | |
539 | 556 | | |
540 | 557 | | |
| |||
1515 | 1532 | | |
1516 | 1533 | | |
1517 | 1534 | | |
| 1535 | + | |
| 1536 | + | |
| 1537 | + | |
| 1538 | + | |
| 1539 | + | |
| 1540 | + | |
| 1541 | + | |
| 1542 | + | |
| 1543 | + | |
| 1544 | + | |
| 1545 | + | |
| 1546 | + | |
| 1547 | + | |
| 1548 | + | |
| 1549 | + | |
| 1550 | + | |
| 1551 | + | |
| 1552 | + | |
| 1553 | + | |
| 1554 | + | |
| 1555 | + | |
| 1556 | + | |
| 1557 | + | |
| 1558 | + | |
| 1559 | + | |
| 1560 | + | |
| 1561 | + | |
| 1562 | + | |
| 1563 | + | |
| 1564 | + | |
| 1565 | + | |
| 1566 | + | |
| 1567 | + | |
| 1568 | + | |
| 1569 | + | |
| 1570 | + | |
| 1571 | + | |
| 1572 | + | |
| 1573 | + | |
1518 | 1574 | | |
1519 | 1575 | | |
1520 | 1576 | | |
1521 | 1577 | | |
1522 | 1578 | | |
1523 | 1579 | | |
1524 | 1580 | | |
| 1581 | + | |
| 1582 | + | |
| 1583 | + | |
| 1584 | + | |
1525 | 1585 | | |
1526 | 1586 | | |
| 1587 | + | |
| 1588 | + | |
| 1589 | + | |
| 1590 | + | |
| 1591 | + | |
| 1592 | + | |
1527 | 1593 | | |
1528 | 1594 | | |
1529 | 1595 | | |
| |||
0 commit comments