Fix race condition during socket creation