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

OSError: Bad file descriptor in madbg/debugger.py, sometimes, when connecting to running process #50

Open
DavidAntliff opened this issue Aug 13, 2023 · 1 comment

Comments

@DavidAntliff
Copy link

DavidAntliff commented Aug 13, 2023

Not sure if this is expected or a known issue. Please take the following program, loop.py:

import time

i = 0
while True:
    i = i + 1
    print(i)
    time.sleep(0.001)

Run it: python loop.py and it will start outputting sequential numbers.

In another shell, run madbg (1.3.2):

$ madbg attach $(pgrep -f loop.py)

The shell running loop.py will typically stop with something like:

Waiting for debugger client on 127.0.0.1:3513
Debugger client connected from ('127.0.0.1', 46754)

And the madbg shell will show an ipdb> prompt - so far so good. Hit 'Q' + Enter to quit ipdb and the loop.py count will continue.

Repeat running madbg attach a few times, eventually the following will occur as loop.py terminates:

5380
5381
5382
Traceback (most recent call last):
  File loop.py, line 5, in <module>
    while True:
  File loop.py, line 5, in <module>
    while True:
  File venv/lib/python3.10/site-packages/madbg/debugger.py, line 64, in trace_dispatch
    return super().trace_dispatch(frame, event, arg)
  File /usr/lib/python3.10/bdb.py, line 90, in trace_dispatch
    return self.dispatch_line(frame)
  File /usr/lib/python3.10/bdb.py, line 114, in dispatch_line
    self.user_line(frame)
  File /usr/lib/python3.10/pdb.py, line 262, in user_line
    self.interaction(frame, None)
  File venv/lib/python3.10/site-packages/IPython/core/debugger.py, line 337, in interaction
    OldPdb.interaction(self, frame, traceback)
  File /usr/lib/python3.10/pdb.py, line 356, in interaction
    self.print_stack_entry(self.stack[self.curindex])
  File venv/lib/python3.10/site-packages/IPython/core/debugger.py, line 411, in print_stack_entry
    print(self.format_stack_entry(frame_lineno, '', context), file=self.stdout)
OSError: [Errno 9] Bad file descriptor
Exception ignored in: <module 'threading' from '/usr/lib/python3.10/threading.py'>
Traceback (most recent call last):
  File /usr/lib/python3.10/threading.py, line 1537, in _shutdown
    atexit_call()
  File /usr/lib/python3.10/contextlib.py, line 584, in close
    self.__exit__(None, None, None)
  File /usr/lib/python3.10/contextlib.py, line 576, in __exit__
    raise exc_details[1]
  File /usr/lib/python3.10/contextlib.py, line 561, in __exit__
    if cb(*exc_details):
  File /usr/lib/python3.10/contextlib.py, line 142, in __exit__
    next(self.gen)
  File venv/lib/python3.10/site-packages/madbg/debugger.py, line 170, in start_from_new_connection
    with cls.start(sock.fileno()) as debugger:
  File /usr/lib/python3.10/contextlib.py, line 142, in __exit__
    next(self.gen)
  File venv/lib/python3.10/site-packages/madbg/debugger.py, line 147, in start
    print('Closing connection', file=slave_writer, flush=True)
OSError: [Errno 9] Bad file descriptor

The madbg instance will have simply terminated with no output, error code 0.

My environment:

$ python --version
3.10.6

$ pip list  | grep hypno
hypno                  1.0.3

$ pip list | grep pyinjector
pyinjector             1.3.0

$ pip list | grep ipython
ipython                8.3.0

$ lsb_release -a
No LSB modules are available.
Distributor ID:	Ubuntu
Description:	Ubuntu 22.04.2 LTS
Release:	22.04
Codename:	jammy
@kmaork
Copy link
Owner

kmaork commented Aug 14, 2023

Thank you for all the details! I'm working on a new version for madbg, in which a lot of the code is changed. I think I'll wait to see if it happens in the new version as well.

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