Commit 6788a0d
committed
fix(room): release remote participants when the room is closed
`RoomSession::close` unpublished the local participant's tracks and then dropped
the remote participant map. Dropping the map does not release the participants:
every remote publication registers callbacks that hold the participant which owns
them — `on_subscribed`/`on_unsubscribed` capture the `RemoteParticipant`, and
`on_muted`/`on_unmuted` capture it through the publication map — so each remote
participant is kept alive by a cycle through its own publications.
A leaked participant holds `Arc<RtcEngine>`, so it pins the whole engine, its peer
connections and the WebRTC runtime: exactly what commit 16530d2 set out to
release. Each connect/close cycle leaked another one.
`handle_participant_disconnect` already unregisters these when a peer actually
leaves, but it also emits ParticipantDisconnected and TrackUnpublished. The peers
have not left here — the room is closing — so unregister directly instead, leaving
the event stream unchanged.
Two ordering constraints make this correct:
- The teardown runs after `room_handle` has been joined. `room_task` is what
inserts remote participants, so draining the map any earlier would let an engine
event queued behind the close repopulate it, and those participants would never
be visited.
- Each publication is unregistered before its track is detached.
`RemoteTrackPublication::set_track(None)` invokes the unsubscribe handler *before*
clearing it, and that handler dispatches TrackUnsubscribed carrying strong clones
of the participant and track. Clearing the handlers first keeps teardown silent,
so a receiver the application has stopped draining cannot pin the participant
through a queued event.
`test_close_releases_room_session` did not catch any of this because it runs with a
single participant and no tracks, so neither cycle is ever formed. The new test uses
two participants with a published, subscribed track, keeps its event receiver alive
and undrained across the close, and asserts via a drop probe that the remote
participant's internals are released.1 parent 25931c7 commit 6788a0d
3 files changed
Lines changed: 103 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1201 | 1201 | | |
1202 | 1202 | | |
1203 | 1203 | | |
| 1204 | + | |
| 1205 | + | |
| 1206 | + | |
| 1207 | + | |
| 1208 | + | |
| 1209 | + | |
| 1210 | + | |
| 1211 | + | |
| 1212 | + | |
| 1213 | + | |
| 1214 | + | |
| 1215 | + | |
| 1216 | + | |
| 1217 | + | |
| 1218 | + | |
| 1219 | + | |
| 1220 | + | |
| 1221 | + | |
| 1222 | + | |
| 1223 | + | |
| 1224 | + | |
| 1225 | + | |
| 1226 | + | |
| 1227 | + | |
| 1228 | + | |
1204 | 1229 | | |
1205 | 1230 | | |
1206 | 1231 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
112 | 112 | | |
113 | 113 | | |
114 | 114 | | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
115 | 124 | | |
116 | 125 | | |
117 | 126 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
17 | | - | |
| 17 | + | |
18 | 18 | | |
19 | | - | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
20 | 23 | | |
21 | | - | |
22 | | - | |
| 24 | + | |
| 25 | + | |
23 | 26 | | |
24 | 27 | | |
25 | 28 | | |
| |||
140 | 143 | | |
141 | 144 | | |
142 | 145 | | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
0 commit comments