Close ports after query