defer conn.close and signal to guard against panic-caused deadlock