Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[3.x] [Net] Remove blocking network address resolution in connect_to_host in websockets #53243

Closed

Conversation

jordo
Copy link
Contributor

@jordo jordo commented Sep 30, 2021

This commit removes blocking address resolution in connect_to_host in websockets. This is similar to what happens in HTTPClient.

Currently a few other peer's implementations of connect_to_host still include a blocking call to resolve_hostname which unfortunately can block in getaddrinfo for an unspecified amount of time. This is not good, considering there is a good chance many projects are calling connect_to_host on the main engine thread.

This PR addresses one of the peers (websocket) with an resolving state, which is similar to what happens in HTTPClient.

I'm hoping eventually we can clean up these connection status state enums into something shared among all the network classes, but until then this and the rest of the network classes connect_to_host implementations should follow what HttpClient does. (Have an intermediate resolving state to avoid blocking in connect_to_host).

As an aside, (as someone who's gone through Apple App review too many times), I'm pretty sure their test environment includes a laggy DNS response env. I have seen app review bring this up a few time with different app submissions, and indeed our project was using the websocket connect_to_host, and ended up pausing the main thread for much too long waiting for a hostname to resolve. This was easily confirmed with the iOS link conditioner, and setting a manual delay for dns resolution time.

@jordo jordo requested a review from a team as a code owner September 30, 2021 03:27
@jordo jordo force-pushed the PR-wsl-connect_to_host branch from 6ab4649 to 7bf08a8 Compare September 30, 2021 03:50
@Calinou Calinou added this to the 3.4 milestone Sep 30, 2021
Copy link
Collaborator

@Faless Faless left a comment

Choose a reason for hiding this comment

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

As mentioned multiple times, changes need to be PRed against the master branch first.

@jordo
Copy link
Contributor Author

jordo commented Sep 30, 2021

#53262 for master

@jordo
Copy link
Contributor Author

jordo commented Sep 30, 2021

fixes #53265 for websocket clients

@akien-mga akien-mga modified the milestones: 3.4, 3.5 Nov 8, 2021
Faless
Faless previously requested changes Dec 15, 2021
Copy link
Collaborator

@Faless Faless left a comment

Choose a reason for hiding this comment

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

I am deeply sorry for the very long review time, I have been sucked up by the work on the replication API.
This change looks okay, it is a bit of a mess that this has to be handled down in every peer separately, but it's definitely an improvement so I would merge this once the review comments are addressed.
Good work 👍

Vector<String> _protocols;
Vector<String> _original_protocols;
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't understand why we need the _original_protocols.
It seems there is already the _protocols variable that could be used.

_connection = _tcp;

_key = WSLPeer::generate_key();
// TODO custom extra headers (allow overriding this too?)
Copy link
Collaborator

Choose a reason for hiding this comment

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

We can remove this TODO since we now support extra headers (was a leftover from the other PR I guess).

@Faless Faless changed the title [NET] Remove blocking network address resolution in connect_to_host in websockets [3.x] [Net] Remove blocking network address resolution in connect_to_host in websockets Dec 15, 2021
@Faless Faless dismissed their stale review December 15, 2021 12:42

I meant to review the master PR, please disregard this review

@akien-mga akien-mga force-pushed the 3.x branch 2 times, most recently from 71cb8d3 to c58391c Compare January 6, 2022 22:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants