Skip to content

Properly wrap OS errors when using trio - #225

Merged
florimondmanca merged 4 commits into
masterfrom
fm/fix-connect-errors
Oct 26, 2020
Merged

Properly wrap OS errors when using trio#225
florimondmanca merged 4 commits into
masterfrom
fm/fix-connect-errors

Conversation

@florimondmanca

@florimondmancaflorimondmanca commented Oct 24, 2020

Copy link
Copy Markdown
Contributor

Closes#224

The problem in #224 turns out to hittrio / anyio+trio for both TCP and UDS.

We were not properly mapping OSError in those places, and this PR fixes that, adding regression tests to our test suite to make sure the proper behavior applies everywhere.

@florimondmancaflorimondmanca added the bug Something isn't working label Oct 24, 2020
@florimondmanca
florimondmanca requested a review from a teamOctober 24, 2020 15:51
@florimondmancaflorimondmanca changed the title Properly wrap errors when connection or DNS resolution failsProperly wrap OS errors when using trioOct 24, 2020

@cdelercdeler left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good for me (with some naming remarks)

),
],
)
async def test_cannot_connect_tcp(backend: str, url) -> None:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

May be we can make it catchy, a-la test_tcp_connection_errors_are_properly_wrapped, like in BDD (then we can omit the comment)



@pytest.mark.anyio
async def test_cannot_connect_uds(backend: str) -> None:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here the same as the TCP test

) -> AsyncSocketStream:
connect_timeout = timeout.get("connect")
unicode_host = hostname.decode("utf-8")
exc_map = {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small nit: we could move the mapping to the class level. That way it's not created on each method call, and also could be shared between open_tcp_stream() and open_uds_stream() since the content is the same.
I see that the other backends have the same issue, so happy to defer this to a followup PR if we think it's worth doing.

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like that this style makes it simple-as-cake to visually keep track of which exactly exceptions we map in each case, and I think moving it to a class variable (further away than from where it's actually used) wouldn't help with readability either. So overall, I'm thinking this may not really be worth a follow-up?

@florimondmanca

Copy link
Copy Markdown
ContributorAuthor

Thanks for the reviews @jcugat and @cdeler. Given the approvals and the working state of this PR I'm moving forward with a plan to release the fixes in a bugfix release, but happy to consider any follow-ups. :)

@florimondmanca
florimondmanca merged commit 0a9575f into masterOct 26, 2020
@florimondmanca
florimondmanca deleted the fm/fix-connect-errors branch October 26, 2020 14:12
@florimondmancaflorimondmanca mentioned this pull request Nov 4, 2020
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bugSomething isn't working

Development

Successfully merging this pull request may close these issues.

Getting raw exceptions instead of httpcore.ConnectError when using trio

3 participants

@florimondmanca@jcugat@cdeler