in reply to net-ssh-expect is giving error

Isn't that expected?

If you reboot the machine, any SSH connection open will be terminated, including the connection launching the reboot!