Skip to content

Closing an injected XhrIo client also closes caller-owned httpx.AsyncClient #4

Description

@dennisvink

Summary

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

Why this is a problem

If an application passes a shared httpx.AsyncClient into XhrIo, closing that helper unexpectedly shuts down the shared client and breaks unrelated requests.

Where

  • src/python_webchannel/xhr.py

Expected behavior

XhrIo should mirror the same ownership pattern recommended for WebChannel: only close an internally-created client, and leave caller-owned clients open.

Suggested fix

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

Impact

This makes XhrIo unsafe to use with shared HTTP client pools, which is a common pattern in async Python applications.

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