added to check for race conditions of handling a client and upgrading the socket connection

added to check for race conditions of handling a client and upgrading the socket connection