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

Unable to send SIGINT to the remote debugger client process #132

Closed
rsaim opened this issue Mar 3, 2021 · 5 comments
Closed

Unable to send SIGINT to the remote debugger client process #132

rsaim opened this issue Mar 3, 2021 · 5 comments
Assignees
Labels
Harder Issue will require a lot of work to fix High Priority

Comments

@rsaim
Copy link
Collaborator

rsaim commented Mar 3, 2021

reproducer.py

import pyflyby
import sys

def mydebugger(*args, **kwargs):
    kwargs["wait_for_attach"] = True
    pyflyby.debugger(*args, **kwargs)

sys.excepthook = mydebugger

1/0
  1. (Debugged Process) Run the reproducer above
  2. (Debugger client) Try to connect to the process using instructions displayed using the py script - py -D . Let's call this process P2
  3. Send a SIGINT to the P2 process. The terminal won't respond and become unusable.

I'm using zsh. It seems like SIGINT is not sent to the P2 on ctrl+c. However, sending SIGINT from another terminal killed the client and both its children - the gdb and watchdog processes.

Doesn't respond to ctrl+c

$ /usr/local/python/python3.7/bin/py -d 22495
^C

Here, 27991 is the client, 27997 is the gdb process and 27998 is the watchdog process.

raza      27991  72187  0 22:35 pts/68   00:00:00 /usr/local/python/python3.7/bin/python3 /usr/local/python/python3.7/bin/py -d 22495
raza      27997  27991  0 22:35 pts/68   00:00:00 gdb /opt/python/python-3.7/bin/python3.7 -p 22495 -batch -eval-command=call PyGILState_Ensure() -eval-command=call PyRun_SimpleString("__import__('sys').path.insert(0, '/usr/local/python/python3.7/lib64/python3.7/site-packages')") -eval-command=call PyRun_SimpleString("__import__('pyflyby').debugger(tty='/dev/pts/31', on_continue=lambda: __import__('os').kill(27991, 10))") -eval-command=call PyGILState_Release($1)
raza      27998  27991  0 22:35 pts/68   00:00:00 /usr/local/python/python3.7/bin/python3 /usr/local/python/python3.7/bin/py -d 22495

From another terminal

$ kill -2 27991

The debugger client:

$ /usr/local/python/python3.7/bin/py -d 22495
^CTraceback (most recent call last):
  File "/usr/local/python/python3.7/bin/py", line 11, in <module>
    sys.exit(py_main())
  File "/usr/local/python/python3.7/lib64/python3.7/site-packages/pyflyby/_py.py", line 2046, in py_main
    _PyMain(args).run()
  File "/usr/local/python/python3.7/lib64/python3.7/site-packages/pyflyby/_py.py", line 1781, in run
    self._run_action()
  File "/usr/local/python/python3.7/lib64/python3.7/site-packages/pyflyby/_py.py", line 1983, in _run_action
    attach_debugger(int(arg0, 10))
  File "/usr/local/python/python3.7/lib64/python3.7/site-packages/pyflyby/_dbg.py", line 1101, in attach_debugger
    terminal.communicate()
  File "/usr/local/python/python3.7/lib64/python3.7/site-packages/pyflyby/_dbg.py", line 997, in communicate
    pty._copy(self.master_fd)
  File "/opt/python/python-3.7/lib64/python3.7/pty.py", line 136, in _copy
    rfds, wfds, xfds = select(fds, [], [])
KeyboardInterrupt
@asmeurer
Copy link
Collaborator

I'm not really sure how to get the remote debugger working, but it may be instructive to look at how ptyprocess handles keyboard interrupts (see sendintr and _make_eof_intr here https://github.com/pexpect/ptyprocess/blob/master/ptyprocess/ptyprocess.py).

@Carreau Carreau added Harder Issue will require a lot of work to fix High Priority labels Mar 22, 2021
@ericdatakelly ericdatakelly added this to the April 2021 milestone Mar 29, 2021
@asmeurer
Copy link
Collaborator

asmeurer commented Apr 2, 2021

I get this error when I try to run the script

Traceback (most recent call last):
  File "/Users/aaronmeurer/Documents/pyflyby/lib/python/pyflyby/_dbg.py", line 610, in wait_for_debugger_to_attach
    _send_email_with_attach_instructions(arg, mailto, originalpid=originalpid)
  File "/Users/aaronmeurer/Documents/pyflyby/lib/python/pyflyby/_dbg.py", line 757, in _send_email_with_attach_instructions
    s = smtplib.SMTP("localhost")
  File "/Users/aaronmeurer/anaconda3/envs/pyflyby3/lib/python3.8/smtplib.py", line 253, in __init__
    (code, msg) = self.connect(host, port)
  File "/Users/aaronmeurer/anaconda3/envs/pyflyby3/lib/python3.8/smtplib.py", line 339, in connect
    self.sock = self._get_socket(host, port, self.timeout)
  File "/Users/aaronmeurer/anaconda3/envs/pyflyby3/lib/python3.8/smtplib.py", line 308, in _get_socket
    return socket.create_connection((host, port), timeout,
  File "/Users/aaronmeurer/anaconda3/envs/pyflyby3/lib/python3.8/socket.py", line 808, in create_connection
    raise err
  File "/Users/aaronmeurer/anaconda3/envs/pyflyby3/lib/python3.8/socket.py", line 796, in create_connection
    sock.connect(sa)
ConnectionRefusedError: [Errno 61] Connection refused

I don't understand the error. Is it trying to send an email? Clearly there is some step that I'm missing in order to get the remote debugger working.

@ericdatakelly ericdatakelly modified the milestones: April 2021, May 2021 Apr 5, 2021
@Carreau
Copy link
Collaborator

Carreau commented Apr 13, 2021

I can't completely reproduce the issue, but I have an idea of what is causing it.

  • The gdb command will hang in its current state if the Python version you are trying to attach to does not have debug symbols. I'll try to catch this and make sure we fail with a good error message.

It may be that the debug symbols are not installed and this will fix your issue.

Just before the _copy call

pyflyby/_dbg.py", line 997, in communicate :   pty._copy(self.master_fd)

The terminal is set in raw mode which purposefully ignore escape sequences like Ctrl-C and pass them down to the subprocess that actually do the debugging and with which in the end the user is interacting with.

That might not be that easy to fix.

Even with debug symbols I hit an immediate segfault (maybe related to #131), when I try to ensure that GIL is taken via GDB and am working toward fixing the cause of this.

@Carreau Carreau self-assigned this Apr 19, 2021
@ericdatakelly ericdatakelly modified the milestones: May 2021, June 2021 Jun 7, 2021
@Carreau
Copy link
Collaborator

Carreau commented Jun 15, 2021

I believe this should have been fixed by #141 let us know if that's not the case or if there are other issues.

@Carreau Carreau closed this as completed Jun 15, 2021
@sac111gp
Copy link
Collaborator

Internal ticket for reference: Prop#279270

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Harder Issue will require a lot of work to fix High Priority
Projects
None yet
Development

No branches or pull requests

5 participants