Release room list entries resources even if onControllerCreated is cancelled

Use try/finally instead of the awaitClose block, so that the entries stream, the controller and the
dynamic adapters are destroyed even if the suspending onControllerCreated callback is cancelled or
throws before awaitClose is reached.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Benoit Marty
2026-10-09 14:28:17 +02:00
parent 2f7e2316e1
commit 10afe7c18c
@@ -70,9 +70,13 @@ internal fun RoomListInterface.entriesFlow(
listener = listener,
)
val controller = result.controller()
controller.setFilter(initialFilterKind)
onControllerCreated(controller)
awaitClose {
// Use try/finally rather than awaitClose's block, so that the resources are released even if
// onControllerCreated is cancelled or throws before awaitClose is reached
try {
controller.setFilter(initialFilterKind)
onControllerCreated(controller)
awaitClose()
} finally {
result.entriesStream().cancelAndDestroy()
controller.destroy()
result.destroy()