Add proper thread safety. Please let me know if this deadlocks your server.