Skip to content

Fix mismatch of blocking calls inside asynchronous methods #1220

@danielballan

Description

@danielballan

This method is asynchronous but performs a blocking write!

https://github.com/bluesky/tiled/blob/main/tiled/adapters/zarr.py#L148-L156

The read* and write* methods are allowed to be synchronous or asynchronous; when called by the server they are wrapped in a helper function that pushes synchronous methods to a thread:

tiled/tiled/utils.py

Lines 736 to 742 in 0388f21

async def ensure_awaitable(func, *args, **kwargs):
if is_coroutine_callable(func):
return await func(*args, **kwargs)
else:
# run_sync() does not apply **kwargs to func
# https://github.com/agronholm/anyio/issues/414
return await anyio.to_thread.run_sync(functools.partial(func, **kwargs), *args)

But of course this mechanism is thwarted when we put synchronous I/O code inside an asynchronous method. This kind of bug seriously harms the scalability of the server, as the entire event loop will grind to a halt while processing this request.

The methods on this Adapter and others should be reviewed for correctness.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions