You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Problem with recent change to the calling sequence for the function 'ws_socket() #86
The recent change to the calling sequence for the function 'ws_socket(struct ws_server *ws_srv)' causes problems if the 'ws_server' structure is in the stack of the calling function and the function exits after calling a non-blocking 'ws_socket()'.
Previously, the callers 'ws_events' structure was copied the wsServer's 'ws_server' structure. Now, the caller's pointer to it's 'ws_server' structure is placed in the wsServer's 'ws_accept_params' structure.
When the calling function exits, it's 'ws_server' structure becomes undefined. The solution for the caller is to allocate the 'ws_server' structure in local space.
A note of this should be included in the documentation. And maybe the examples like 'echo' should do this instead of using stack allocation.
Hi @grm1209,
Yes, you are correct that the structure pointer is passed to 'ws_accept_params' but the 'ws_server' structure is indeed copied into memory as soon as the thread handling the connection is created.
What must be happening in your case is that the function returns even before this thread is created, and thus the structure is no longer valid. This is a bug and needs to be fixed.
I will address it as soon as possible. Thank you for bringing it to my attention.
Hi @Vaibhav-singh78,
Is your issue related to this one? if not, it would be much better to create a new issue...
Anyway, could you provide more details? your operating system? code used etc? An 'MRE' (Minimal, Reproducible Example) would be very useful to better understand your problem.
Activity
Theldus commentedon Dec 14, 2023
Hi @grm1209,
Yes, you are correct that the structure pointer is passed to '
ws_accept_params' but the 'ws_server' structure is indeed copied into memory as soon as the thread handling the connection is created.What must be happening in your case is that the function returns even before this thread is created, and thus the structure is no longer valid. This is a bug and needs to be fixed.
I will address it as soon as possible. Thank you for bringing it to my attention.
Bug Fix: Race condition between ws_accept() and function return
Theldus commentedon Dec 14, 2023
@grm1209 could you confirm if commit 24e6fae fixes your problem?
Vaibhav-singh78 commentedon Mar 17, 2024
library has problem with socket accepting connection , can you help i am stuck here for two days
Theldus commentedon Mar 18, 2024
Hi @Vaibhav-singh78,
Is your issue related to this one? if not, it would be much better to create a new issue...
Anyway, could you provide more details? your operating system? code used etc? An 'MRE' (Minimal, Reproducible Example) would be very useful to better understand your problem.