Open jonatanklosko opened 4 days ago
Looking at the code WSAStartup
is called once, when the NIF is loaded, whereas WSACleanup
is called in case of errors. The WSAStartup
documentation states:
When it has finished using the services of the Winsock DLL, the application must call WSACleanup to allow the Winsock DLL to free internal Winsock resources used by the application.
So perhaps WSACleanup
ends up being called too eagerly and effectively uninitializes WinSock.
Also, the WSANOTINITIALISED error description says:
[...] or WSACleanup has been called too many times.
Note that I am not familiar with WinSock, so these are my best guesses.
I think you are correct. I used it to "clean up" the last operation, but that is clearly not how its supposed to be used. Thanks for finding this!
Regards, /Micael
Hey @bmk, do you think that once this is fixed, the fix could be backported in a patch release for 26 and 27?
That was my intention.
PR solving this (I hope): bmk/esock/20240924/excessive_use_of_cleanup/otp-19251 Has not run in the daily tests yet.
Describe the bug
After unsuccessful
socket:connect
attempts, socket operations start to return{error,notinitialised}
(corresponds toWSANOTINITIALISED
in WinSock), as if WinSock was no longer initialised.To Reproduce
I narrowed it down to a case where we attempt two connections. Interestingly, after the first failure everything still works as expected, but after the second attempt
socket
breaks altogether.(closing each socket after connect does not help)
Expected behavior
Subsequent
socket:open
to return a new socket.Affected versions
Tested on OTP 27.
Additional context
In case this matters, I am running virtualized ARM Windows 11.