Skip to content

LocalFS.open() uses blocking open() inside async def — intentional design or oversight? #824

Description

@Joaquinriosheredia

Hi,

While analyzing asyncssh with python-vibe-guard, I noticed that
LocalFS.open() in asyncssh/sftp.py is defined as async def
but uses the synchronous open() builtin internally:

@async_context_manager
async def open(self, path: bytes, mode: str,
               block_size: int = -1) -> LocalFile:
    file_obj = open(_to_local_path(path), mode)
    ...
    return LocalFile(file_obj)

In a server handling multiple concurrent SFTP clients on the same
event loop, each call to LocalFS.open() blocks the loop for the
duration of the file open syscall — particularly noticeable on slow
or network-mounted storage.

I wanted to ask before assuming this is a bug: was this a deliberate
design decision (e.g. LocalFS is not intended for high-concurrency
scenarios), or would a fix using asyncio.get_event_loop().run_in_executor()
or aiofiles be welcome?

Tool used: python-vibe-guard
AST-based runtime anti-pattern scanner validated on 902 real repositories.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions