Skip to content

Commit c1a0f70

Browse files
committed
fix deadlock
1 parent 0d3d995 commit c1a0f70

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

marimo/_server/rtc/doc.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -143,9 +143,16 @@ async def remove_client(
143143
cleaner.cancel()
144144
self.loro_docs_cleaners[file_key] = None
145145
# Create a new cleaner with timeout of 60 seconds
146-
self.loro_docs_cleaners[file_key] = asyncio.create_task(
147-
self._clean_loro_doc(file_key, 60.0)
148-
)
146+
self.loro_docs_cleaners[file_key] = None
147+
148+
# Create the cleaner task outside the lock
149+
if (
150+
file_key in self.loro_docs_clients
151+
and len(self.loro_docs_clients[file_key]) == 0
152+
):
153+
self.loro_docs_cleaners[file_key] = asyncio.create_task(
154+
self._clean_loro_doc(file_key, 60.0)
155+
)
149156

150157
async def remove_doc(self, file_key: MarimoFileKey) -> None:
151158
"""Remove a loro doc and all associated clients, without waiting."""

0 commit comments

Comments
 (0)