win_glue DLLMain problems with WSAStartup / WSACleanup

Jeffrey Altman jaltman at columbia.edu
Fri Mar 25 05:14:06 EST 2005


It appears that there is a significant deadlocking problem with the way 
in which we ensure that the Windows sockets API has been initialized
and that it is cleaned up.

In the DllMain() function of our DLLs, we currently call WSAStartup at 
process attach and WSACleanup at process detach.  When the Microsoft
Internet Connection Firewall is enabled, the call to WSACleanup will
produce a deadlock.

According to Microsoft, we cannot make these calls.  Instead, the 
application must initialize Winsock for us or we must initialize it
outside of the DllMain().  This most likely means that we will have
to check all Winsock() api calls to see whether there is a 
WSANOTINITIALISED error and if so call WSAStartup() and then retry
the operation.  By doing so, the most we will leak is one winsock
initialization since as far as I can tell there is no method by which
we can safely perform a WSACleanup().

Thoughts?

Jeffrey Altman


More information about the krbdev mailing list