steep-balloon-41261
08/28/2025, 8:58 AMtall-airline-16756
08/28/2025, 8:58 AMtall-airline-16756
08/28/2025, 8:58 AMtall-airline-16756
08/28/2025, 9:01 AMUnclosed client session usually pops up when an asynchronous session or resource isn’t closed properly. From what you’ve shared, it seems like the hiccup might be around using asyncio.create_task and how the reader object is being handled.
Here are a few friendly tips to help you sort this out:
• Make sure any session or resource (like reader) gets closed after you’re done with it. If reader has a method like close() or aclose(), try calling it inside a finally block within your async_handle_text_stream function.
• Double-check if reader or any other resource in your code needs explicit cleanup. For instance, if reader is an async stream, it’s important to close it properly to avoid any leaks.
• Think about using context managers (like async with) to handle resources that need cleaning up—it makes your life easier!
• Also, make sure all tasks created with asyncio.create_task are awaited or managed properly so they finish up and free their resources.
Here’s a little example of how you might tweak your async_handle_text_stream function to keep things neat and tidy:
async def async_handle_text_stream(reader, participant_identity):
try:
info = reader.info
text = await reader.read_all()
print(f"Received text: {text}")
session.userdata.latest_code = text # Store the latest code update in userdata
print(f"Updated userdata with latest_code: {session.userdata.latest_code}")
finally:
await reader.aclose() # Make sure the reader is properly closed
If you’re still running into trouble after this, just give me a shout and we’ll dig into it together!fierce-jordan-44682
08/28/2025, 9:11 AMtall-airline-16756
08/28/2025, 9:11 AMTextStreamReader object doesn’t have an aclose() method because it handles its own lifecycle for you—no need to worry about closing it manually. You can simply consume the data in one of these ways:
• Step-by-step, with a loop:
async for chunk in reader:
print(chunk)
• Or all at once, by using await reader.read_all().
Either way, the reader will naturally stop and finish when the sender closes the stream. If something’s still not working right, just let me know, and we’ll figure it out together!
Sources: examples/data-streams/data_streams.py | lib/src/core/room.dart | Sending text | LiveKit Docs