Fabric: Connection.sudo() sometimes raises ThreadException/OSError instead of AuthFailure

Created on 18 Feb 2020  ·  5Comments  ·  Source: fabric/fabric

invoke.exceptions.ThreadException: 
Saw 1 exceptions within threads (OSError):


Thread args: {'kwargs': {'buffer_': ['[sudo] password: '],
            'hide': False,
            'output': <_io.TextIOWrapper name='<stderr>' mode='w' encoding='UTF-8'>},
 'target': <bound method Runner.handle_stderr of <fabric.runners.Remote object at 0x7f066e63a9e8>>}

Traceback (most recent call last):

  File "/home/amezin/test/.venv/lib/python3.6/site-packages/invoke/util.py", line 233, in run
    super(ExceptionHandlingThread, self).run()

  File "/usr/lib/python3.6/threading.py", line 864, in run
    self._target(*self._args, **self._kwargs)

  File "/home/amezin/test/.venv/lib/python3.6/site-packages/invoke/runners.py", line 750, in handle_stderr
    buffer_, hide, output, reader=self.read_proc_stderr

  File "/home/amezin/test/.venv/lib/python3.6/site-packages/invoke/runners.py", line 717, in _handle_output
    self.respond(buffer_)

  File "/home/amezin/test/.venv/lib/python3.6/site-packages/invoke/runners.py", line 884, in respond
    self.write_proc_stdin(response)

  File "/home/amezin/test/.venv/lib/python3.6/site-packages/invoke/runners.py", line 960, in write_proc_stdin
    self._write_proc_stdin(data.encode(self.encoding))

  File "/home/amezin/test/.venv/lib/python3.6/site-packages/fabric/runners.py", line 67, in _write_proc_stdin
    return self.channel.sendall(data)

  File "/home/amezin/test/.venv/lib/python3.6/site-packages/paramiko/channel.py", line 846, in sendall
    sent = self.send(s)

  File "/home/amezin/test/.venv/lib/python3.6/site-packages/paramiko/channel.py", line 801, in send
    return self._send(s, m)

  File "/home/amezin/test/.venv/lib/python3.6/site-packages/paramiko/channel.py", line 1198, in _send
    raise socket.error("Socket is closed")

OSError: Socket is closed

Most helpful comment

@matt-hayden After hours of debugging you just saved me from a mental breakdown. I would also like to add that I only got this error while using multiprocessing.Process even if it's just one process.

All 5 comments

I think what you might be seeing is a different error: I don't think it's getting to the sudo auth phase. I'm seeing this on Python 2.7 but only when stdin is redirected from /dev/null. Maybe try again with pty=True?

@matt-hayden After hours of debugging you just saved me from a mental breakdown. I would also like to add that I only got this error while using multiprocessing.Process even if it's just one process.

@matt-hayden I've seen this issue on python 3.6, ssh'ing into local Ubuntu 18.04 container (with openssh sshd running in it). The same 'sudo' command in exactly the same configuration was working correctly 99% of the time (raising AuthFailure) and raising OSError in the remaining 1%.
I can't remember if pty was set to True.

Anyway, I'm not using fabric now, and I don't have time to verify that this issue is still present. So I guess I should close the issue

The error happened, again and yes I was also using a docker container

@luke-goddard , if it occurred within paramiko (like the traceback above) then maybe this is more appropriate as an issue in the paramiko project.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

bitprophet picture bitprophet  ·  6Comments

TimotheeJeannin picture TimotheeJeannin  ·  3Comments

supriyopaul picture supriyopaul  ·  4Comments

haydenflinner picture haydenflinner  ·  5Comments

SamuelMarks picture SamuelMarks  ·  3Comments