#Python concurrent connection usage

1 messages · Page 1 of 1 (latest)

patent siren
#

What's the correct way to call dagger under FastAPI server.

Right now having
async with dagger.connection(dagger.Config(log_output=open(os.devnull, "w"))):

inside api handler results in frequent

dagger.ClientConnectionError: Failed to establish client connection to the Dagger session: No active engine session to connect to

Any recipe to keep clean session active during application lifetime that I'm no aware of?

stray jacinth
chilly venture
patent siren
#

The issue in isolation is illustrated here

async def dummy_task():
    async with dagger.connection(dagger.Config(log_output=open(os.devnull, "w"))):
        await anyio.sleep(1.0)


async def dummy_main():
    async with anyio.create_task_group() as tg:
        for i in range(10):
            tg.start_soon(dummy_task)

Any entry into context manager causes client to break.

Exactly this happens whenever any fastapi endpoints are hit concurrently.

I solved the problem using isolated clients

async with dagger.Connection(dagger.Config(log_output=open(os.devnull, "w"))) as client:

However maybe better solutions exist.