Fix corner case socket undefined bugs