Prevent closing undefined socket