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

Client Get operation stalls in getaddrinfo when network is down #1601

Open
TheMostDiligent opened this issue Jun 27, 2023 · 6 comments
Open

Comments

@TheMostDiligent
Copy link

Hello!

We are seeing the following issue when the network is completely unavailable: the Get operations stalls in the getaddrinfo for about 30 seconds. We set the connection timeout and read timeout, but they don't have any effect.

Is it possible that this logic also respects the connection timeout?

@yhirose
Copy link
Owner

yhirose commented Jun 27, 2023

@TheMostDiligent thanks for the feedback. As far as I know, getaddrinfo is a blocking function and doesn't provide timeout option. So there is no way for me to deal with it... Do you know how other HTTP libraries handle this situation?

@TheMostDiligent
Copy link
Author

I am not very profound in HTTP handling. However, I tried to research the subject a bit and apparently there is an alternative function: getaddrinfo_a that supports asynchronous wait mode (GAI_NOWAIT).
In this mode, the function exits immediately and an event is triggered when the operation completes. I think this will allow to wait for the event in the loop and abort the loop if timeout elapses. Or even better, if the user-provided callback returns false similar to the callback of the Get function.

@yhirose
Copy link
Owner

yhirose commented Jun 27, 2023

It looks like only Linux supports it... How could it be possible to do the same in Windows and MacOS?

@TheMostDiligent
Copy link
Author

It looks like only Linux supports it

It does seem so. On Mac, there is DNSServiceGetAddrInfo that allows async wait. This article describes it in detail. Looks like it is quite a hassle to implement this...

On Windows, I actually did not see that problem.

@yhirose
Copy link
Owner

yhirose commented Jun 28, 2023

It seems like we may use GetAddrInfoEx which supports timeout parameter.
https://learn.microsoft.com/en-us/windows/win32/api/ws2tcpip/nf-ws2tcpip-getaddrinfoexw

In any case, supporting this feature on all three platforms and ensuring they work correctly will not likely be an easy task for me. So please don't expect me to implement it in the near future. A pull request is always welcome! :)

@yhirose
Copy link
Owner

yhirose commented Sep 8, 2024

This stackoverflow post is helpful to write thread timeout code.
https://stackoverflow.com/questions/40550730/how-to-implement-timeout-for-function-in-c

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

No branches or pull requests

2 participants