Potential deadlock bug in free socket server framework
The free version of the socket server framework contained code that could cause a deadlock during connection closure if you also have a lock in your derived class.
There’s a lock taken out in
CSocketServer::Socket::IsValid() that isn’t really required and which can cause a deadlock if you have your own lock in your derived class which you lock in
OnConnectionReset() or other server callbacks and which is also locked when you call into the framework via
Write() or other calls. The deadlock is due to the lock sequencing; when calling into the framework your lock is locked and then the socket’s lock is locked when
IsValid() is called, when the framework’s calling in to you it does so with the socket’s lock locked and so your lock is acquired after the socket’s lock.
The fix is to remove the lock acquisition in
IsValid() so that the socket’s lock is not locked when you call into the framework to
Write() or to issue a
This is now fixed and the updated source can be downloaded from here.