Ignore broken pipe errors if the sshpass process has exited (#16515)

This fix prevents a broken pipe exception from occurring when password-less
SSH is configured and the sshpass process exits and closes the pipe before
the password is written to the pipe.
This commit is contained in:
graywulf 2016-06-30 16:39:30 -07:00 committed by Brian Coca
parent b3ca0c02c5
commit 9b7d782abb

View file

@ -19,6 +19,7 @@
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
import errno
import fcntl
import os
import pipes
@ -346,7 +347,12 @@ class Connection(ConnectionBase):
if self._play_context.password:
os.close(self.sshpass_pipe[0])
os.write(self.sshpass_pipe[1], "{0}\n".format(to_bytes(self._play_context.password)))
try:
os.write(self.sshpass_pipe[1], "{0}\n".format(to_bytes(self._play_context.password)))
except OSError as e:
# Ignore broken pipe errors if the sshpass process has exited.
if e.errno != errno.EPIPE or p.poll() is None:
raise
os.close(self.sshpass_pipe[1])
## SSH state machine