Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bare exception in xonsh when executing process via sudo #2883

Closed
eode opened this issue Oct 15, 2018 · 2 comments
Closed

bare exception in xonsh when executing process via sudo #2883

eode opened this issue Oct 15, 2018 · 2 comments

Comments

@eode
Copy link
Contributor

eode commented Oct 15, 2018

When running a process via 'sudo', an exception is raised sometimes:

xonsh: To log full traceback to a file set: $XONSH_TRACEBACK_LOGFILE = <filename>
Traceback (most recent call last):
  File "/usr/local/lib/python3.6/dist-packages/xonsh/base_shell.py", line 360, in default
    run_compiled_code(code, self.ctx, None, "single")
  File "/usr/local/lib/python3.6/dist-packages/xonsh/codecache.py", line 67, in run_compiled_code
    func(code, glb, loc)
  File "./foo.xsh", line 1, in <module>
  File "./foo.xsh", line 21, in destroy_containers
    sudo docker container stop @(container.hash)
  File "/usr/local/lib/python3.6/dist-packages/xonsh/built_ins.py", line 946, in subproc_captured_hiddenobject
    return run_subproc(cmds, captured="hiddenobject")
  File "/usr/local/lib/python3.6/dist-packages/xonsh/built_ins.py", line 898, in run_subproc
    pause_call_resume(proc, builtins.__xonsh__.shell.settitle)
  File "/usr/local/lib/python3.6/dist-packages/xonsh/proc.py", line 2416, in pause_call_resume
    p.send_signal(signal.SIGSTOP)
  File "/usr/lib/python3.6/subprocess.py", line 1580, in send_signal
    os.kill(self.pid, sig)
PermissionError: [Errno 1] Operation not permitted

This does not happen every time, but it's reasonably consistent.  Race?

The actual code run is sudo docker container stop @(container.hash), where container.hash is just a namedtuple containing a text string.

This is on an Amazon Ubuntu AMI, t2.micro.

xonfig

+------------------+---------------------+
| xonsh            | 0.8.0               |
| Git SHA          | aca294b8            |
| Commit Date      | Oct 7 09:53:16 2018 |
| Python           | 3.6.6               |
| PLY              | 3.9                 |
| have readline    | True                |
| prompt toolkit   | None                |
| shell type       | readline            |
| pygments         | None                |
| on posix         | True                |
| on linux         | True                |
| distro           | Ubuntu              |
| on darwin        | False               |
| on windows       | False               |
| on cygwin        | False               |
| on msys2         | False               |
| is superuser     | False               |
| default encoding | utf-8               |
| xonsh encoding   | utf-8               |
| encoding errors  | surrogateescape     |
+------------------+---------------------+

Expected Behavior

An exception should only be raised if my code is wrong.

Current Behavior

An exception is raised for some other reason, shown in the above traceback.

Steps to Reproduce

This is the exact code:

from collections import namedtuple

Container = namedtuple('Container', 'hash, name')
def containers(name=None):
    containers = [
        Container(line.split()[0],
                  line.split()[-1],
        ) 
        for line in $(sudo docker container ls).split('\n') 
        if line.strip()
    ][1:]
    if name is not None:
        for container in containers:
            if container.name == name: return container
        return None
    return containers

def destroy_containers():
    for container in containers():
        sudo docker container stop @(container.hash)
    sudo docker container prune
@eode eode changed the title bare exception from attempting to send SIGSTOP to root process bare exception in xonsh when executing process via sudo Oct 15, 2018
@eode
Copy link
Contributor Author

eode commented Oct 15, 2018

This also occurs when just executing a command on the command-line.

$ sudo docker container stop foo
xonsh: To log full traceback to a file set: $XONSH_TRACEBACK_LOGFILE = <filename>
Traceback (most recent call last):
  File "/usr/local/lib/python3.6/dist-packages/xonsh/base_shell.py", line 360, in default
    run_compiled_code(code, self.ctx, None, "single")
  File "/usr/local/lib/python3.6/dist-packages/xonsh/codecache.py", line 67, in run_compiled_code
    func(code, glb, loc)
  File "<xonsh-code>", line 1, in <module>
  File "/usr/local/lib/python3.6/dist-packages/xonsh/built_ins.py", line 946, in subproc_captured_hiddenobject
    return run_subproc(cmds, captured="hiddenobject")
  File "/usr/local/lib/python3.6/dist-packages/xonsh/built_ins.py", line 898, in run_subproc
    pause_call_resume(proc, builtins.__xonsh__.shell.settitle)
  File "/usr/local/lib/python3.6/dist-packages/xonsh/proc.py", line 2416, in pause_call_resume
    p.send_signal(signal.SIGSTOP)
  File "/usr/lib/python3.6/subprocess.py", line 1580, in send_signal
    os.kill(self.pid, sig)
PermissionError: [Errno 1] Operation not permitted

In either case (in a function, or on the cli) this freezes the XONSH instance, which must be sent a kill -9.

@scopatz
Copy link
Member

scopatz commented Oct 20, 2018

Thanks for reporting this @eode!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants