Prevent socket leak in ThreadSocketHandler.