Added a lock on the client handler as well as unwind protect to prevent the port from being held after the loop is exited in main