Skip to content

If start_tls raises exception connection is retained in pool as connecting #431

Description

@elupus

I was investigating #117 since i'm hit with that. But since code has been very much refactored, it doesn't make sense anymore. However something similar may remain.

The following test fails for example. I don't think the stream should remain in pool if start_tls raises.

@pytest.mark.anyio
@unittest.mock.patch("httpcore.backends.mock.AsyncMockStream.start_tls")
async def test_connection_pool_with_exception_on_start(start_tls_mock: unittest.mock.MagicMock):
    """
    HTTP/1.1 requests that result in an exception should not be returned to the
    connection pool.
    """
    start_tls_mock.side_effect = Exception()
    network_backend = AsyncMockBackend([b"Wait, this isn't valid HTTP!"])

    async with AsyncConnectionPool(network_backend=network_backend) as pool:
        # Sending an initial request, which once complete will not return to the pool.
        with pytest.raises(Exception):
            await pool.request(
                "GET", "https://example.com/"
            )

        info = [repr(c) for c in pool.connections]
        assert info == []

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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