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

Respect socket's non blocking connect #1898

Open
aviramha opened this issue Sep 4, 2023 · 3 comments
Open

Respect socket's non blocking connect #1898

aviramha opened this issue Sep 4, 2023 · 3 comments
Assignees

Comments

@aviramha
Copy link
Member

aviramha commented Sep 4, 2023

Current implementation of the connect detour always waits for the other side to accept before it returns, while most applications nowadays set the socket to non blocking, then connect should immediately return with EINPROGRESS error code, indicating that the connect is in progress.
We can improve our implementation to check if socket is non blocking, and if it is, we setup the mirror listen socket, but don't accept until agent returns the result, to reproduce similar behavior (as much as possible).

@Razz4780
Copy link
Contributor

It would be a bit tricky to implement it this way. The usual flow is to call connect and expect EINPROGRESS, then use poll to wait for result. getsockopt can also be used to get connected/error state of the socket. We'd have to asynchronously let the layer know that the listener is ready (which doesn't fit well into our request-response model and lack of background threads :X)

A simpler solution would be to follow the usual TCP proxy pattern - eagerly accept connection, kill it if we fail to connect to the real peer

@aviramha
Copy link
Member Author

Why is it tricky though?
Layer sends ConnectRequest
intProxy responds ConnectInProgress
layer continues
Intproxy accepts connection only after connection is really made on the remote side, if not returns error

@Razz4780
Copy link
Contributor

We can improve our implementation to check if socket is non blocking, and if it is, we setup the mirror listen socket, but don't accept until agent returns the result

Aaaah sorry. Yes. This should work

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
3 participants