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

zsys_set_thread_name_prefix() is not valid after creating sockets #2196

Open
wvalcke opened this issue Aug 24, 2021 · 5 comments
Open

zsys_set_thread_name_prefix() is not valid after creating sockets #2196

wvalcke opened this issue Aug 24, 2021 · 5 comments
Labels

Comments

@wvalcke
Copy link

wvalcke commented Aug 24, 2021

When compiling some test software using libzmq (version 4.3.4) & czmq (version 4.2.1) everything runs fine under Linux.
Running the same software gives an error under Windows:
zsys_set_thread_name_prefix() is not valid after creating sockets
Although the software seems to run fine under Windows too. Reading the sources it seems the function is to be used under Linux only, but in my code i do not call this directly. Should i worry under Windows with this error ?

@wvalcke
Copy link
Author

wvalcke commented Aug 25, 2021

The problem seems to be related to automatic context creation inside czmq. When the first socket or actor is created and no context exists, it will internally create one. In my software at startup, there were multiple (own created threads, not using zactor) which initialized a socket. So the context creation was being done by one (or more) threads at the same time. I think a race condition exists with this in czmq. I solved the problem by creating the context up front, by putting at the start of main zsys_init(). This creates the context by the main thread, afterwards the other threads start creating sockets. Then the problem went away.

@sphaero
Copy link
Contributor

sphaero commented Dec 21, 2021

Did you also try adding zsys_init()

It seems it is fixed for you, so can we close this?

@wvalcke
Copy link
Author

wvalcke commented Dec 21, 2021

For me it worked by making sure zsys_init() is put as the first function to execute in main(). For me this issue can be closed, but i still have the feeling that the automatic context creation handled by czmq is not correct. Why do we need zsys_init()? It is a bit contradictory with the automatic context creation philosopy of czmq. The documentation gives you the feeling you do not need to worry about context creation, but to me this is not correct. At least not when using multiple threads which create sockets at the same time. I think the problem is that the automatic context creation inside czmq does not handle it correctly when multiple threads are involved.

@sphaero
Copy link
Contributor

sphaero commented Dec 21, 2021

I feel you. But we'd need to dive deeper to get to a compatible fix or better documentation. You case could also be an edge case. Perhaps some notes in the docs might help as well. We really appreciate PRs

@stale
Copy link

stale bot commented Apr 16, 2022

This issue has been automatically marked as stale because it has not had recent activity for 90 days. It will be closed if no further activity occurs within 21 days. Thank you for your contributions.

@stale stale bot added the stale label Apr 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants