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

zpoller_wait() will fail if WiFi networks are switched or after Windows sleep and even rebuilding all sockets doesn't make it recover #2276

Open
devlpr opened this issue Dec 9, 2023 · 9 comments

Comments

@devlpr
Copy link

devlpr commented Dec 9, 2023

I'm currently trying to figure out why zpoller_wait() fails after either Windows going to sleep and wakes back up or when switching WiFi networks between two available ones.

Context: Windows 11, C++, czmq 4.3.3 and 4.3.5, using curve encryption, user facing UI application

The application works perfectly until the machine goes to sleep or the WiFi network is switched to a different one. The issue manifests as zpoller_wait() not returning a valid socket. Restarting the application makes it recover, so I know the issue is not on the server side.

I have tried destroying the pollers, sockets, and every other zmq construct in the client and nothing allows it to recover until a full application restart. Is there some latent state somewhere holding onto the old system resources? If the resources could be re-enumerated to refresh that state it seems like it would work.

I've been running it through the debugger but it isn't clear to me what is happening yet.

@sphaero
Copy link
Contributor

sphaero commented Mar 8, 2024

Windows is a bit of second class citizen I'm afraid. We just don't have much Windows devs I guess. I'm willing to have a look as well but I only have windows build hosts which never sleep. Do you have a code example showing the bug?

@devlpr
Copy link
Author

devlpr commented Mar 9, 2024

I'll see if I can create one. I'm 95% on Linux as well. Windows is not my favorite, but people want Windows software still so I need to support the use-case.

@Asmod4n
Copy link
Contributor

Asmod4n commented Mar 22, 2024

This is apparently how libuv does it: https://github.com/libuv/libuv/blob/master/src/win/detect-wakeup.c

@sphaero
Copy link
Contributor

sphaero commented Mar 22, 2024

Thanks for the ref! Seems only relevant for Win8 and later. Docs here: https://learn.microsoft.com/en-us/windows/win32/api/powerbase/nf-powerbase-powerregistersuspendresumenotification

@devlpr
Copy link
Author

devlpr commented Mar 23, 2024

Any idea what code would need to be registered there? If I know what needs to be added I can do the PR. I just don't know where the code is that does the enumeration on Windows. Any information is appreciated. Happy to contribute if I understand what to do.

@devlpr
Copy link
Author

devlpr commented Mar 23, 2024

I see some uses of GetAdaptersAddresses in libzmq/src/ip_resolver.cpp and czmq/src/ziflist.c. The use in ziflist.c seems most pertinent with the comment "// Helper to reload network interfaces from system". That seems to be what needs to happen here. Can anybody confirm that as the correct function to run on wake-up? If so, the next question will be what list to update with it.

@devlpr
Copy link
Author

devlpr commented Mar 23, 2024

On second thought, it seems that the ip_resolver.cpp usage ends up getting called in zpoller.c in s_rebuild_poll_set(). That's in the code path of zpoller_wait, which may make more sense.

@sphaero
Copy link
Contributor

sphaero commented Mar 25, 2024

You also could look into how zloop rebuilds the pollset if it is of any relevance.

s_rebuild_pollset (zloop_t *self)

However this might be one that needs to be done in libzmq as the sockets might need to be recreated?

@sphaero
Copy link
Contributor

sphaero commented May 8, 2024

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

No branches or pull requests

3 participants