Skip to content

Closing a WebChannel also closes caller-owned httpx.AsyncClient #1

@dennisvink

Description

@dennisvink

Summary

WebChannel accepts an optional injected httpx.AsyncClient, but close() always calls self._client.aclose().

Why this is a problem

If an application shares one httpx.AsyncClient across multiple transports or uses it elsewhere, closing a single WebChannel instance unexpectedly shuts down the shared client and breaks unrelated requests.

Where

  • src/python_webchannel/channel.py

Expected behavior

The channel should only close an internally-created client. If the client was injected by the caller, ownership should remain with the caller.

Suggested fix

Track client ownership in __init__ (for example, self._owns_client = http_client is None) and only call aclose() from close() when the client was created internally.

Impact

This can cause hard-to-debug connection errors in apps that correctly reuse httpx.AsyncClient instances.

Metadata

Metadata

Assignees

No one assigned

    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