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

ignore ESRCH on processes to be killed #2

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

pavlix
Copy link
Collaborator

@pavlix pavlix commented Oct 12, 2016

This patch has been rejected but I'm still using it and this pull request will serve a new discussion. From the stacktrace below you can see that it's debugger.quit() procedure we are talking about. Anything can happen during that procedure as we are killing a number of processes that depend on each other and do all sorts of stuff including quitting themselves before being killed by the debugger.

In my opinion if the caller asks the debugger to quit, the debugger should be able to do that. Not catching an exception means that debugger.quit() doesn't even finish its job and bad things can happen like left over processes and stuff like that. If special care is expected on the caller side, debugger.quit() documentation should probably be updated.

Sometimes a debugged process is already gone when python-ptrace performs
steps to terminate it. In that case we need to gracefully ignore any
ESRCH errors.

This issue was discovered when running network-testing1 and resulted
in the following traceback.

Traceback (most recent call last):
  File "./test-client-server", line 5, in <module>
    main()
  File "/home/pavlix/oss/network-testing/network_testing/client_server.py", line 55, in main
    suite.run()
  File "/home/pavlix/oss/network-testing/network_testing/test_suite.py", line 431, in run
    testcase.run()
  File "/home/pavlix/oss/network-testing/network_testing/test_suite.py", line 391, in run
    scenario.run()
  File "/home/pavlix/oss/network-testing/network_testing/test_suite.py", line 172, in run
    debugger.quit()
  File "/home/pavlix/oss/network-testing/network_testing/debug.py", line 198, in quit
    super(SyscallDebugger, self).quit()
  File "/usr/lib64/python3.4/site-packages/ptrace/debugger/debugger.py", line 105, in quit
    process.terminate()
  File "/usr/lib64/python3.4/site-packages/ptrace/debugger/process.py", line 330, in terminate
    self.waitExit()
  File "/usr/lib64/python3.4/site-packages/ptrace/debugger/process.py", line 351, in waitExit
    self.cont(signum)
  File "/usr/lib64/python3.4/site-packages/ptrace/debugger/process.py", line 717, in cont
    ptrace_cont(self.pid, signum)
  File "/usr/lib64/python3.4/site-packages/ptrace/binding/func.py", line 212, in ptrace_cont
    ptrace(PTRACE_CONT, pid, 0, signum)
  File "/usr/lib64/python3.4/site-packages/ptrace/binding/func.py", line 148, in ptrace
    raise PtraceError(message, errno=errno, pid=pid)
ptrace.error.PtraceError: ptrace(cmd=7, pid=12894, 0, 133) error #3: No such process

Sometimes a debugged process is already gone when python-ptrace performs
steps to terminate it. In that case we need to gracefully ignore any
`ESRCH` errors.

This issue was discovered when running network-testing[1] and resulted
in the following traceback.

    Traceback (most recent call last):
      File "./test-client-server", line 5, in <module>
        main()
      File "/home/pavlix/oss/network-testing/network_testing/client_server.py", line 55, in main
        suite.run()
      File "/home/pavlix/oss/network-testing/network_testing/test_suite.py", line 431, in run
        testcase.run()
      File "/home/pavlix/oss/network-testing/network_testing/test_suite.py", line 391, in run
        scenario.run()
      File "/home/pavlix/oss/network-testing/network_testing/test_suite.py", line 172, in run
        debugger.quit()
      File "/home/pavlix/oss/network-testing/network_testing/debug.py", line 198, in quit
        super(SyscallDebugger, self).quit()
      File "/usr/lib64/python3.4/site-packages/ptrace/debugger/debugger.py", line 105, in quit
        process.terminate()
      File "/usr/lib64/python3.4/site-packages/ptrace/debugger/process.py", line 330, in terminate
        self.waitExit()
      File "/usr/lib64/python3.4/site-packages/ptrace/debugger/process.py", line 351, in waitExit
        self.cont(signum)
      File "/usr/lib64/python3.4/site-packages/ptrace/debugger/process.py", line 717, in cont
        ptrace_cont(self.pid, signum)
      File "/usr/lib64/python3.4/site-packages/ptrace/binding/func.py", line 212, in ptrace_cont
        ptrace(PTRACE_CONT, pid, 0, signum)
      File "/usr/lib64/python3.4/site-packages/ptrace/binding/func.py", line 148, in ptrace
        raise PtraceError(message, errno=errno, pid=pid)
    ptrace.error.PtraceError: ptrace(cmd=7, pid=12894, 0, 133) error vstinner#3: No such process

[1]: https://github.com/pavlix/network-testing
@pavlix
Copy link
Collaborator Author

pavlix commented Oct 12, 2016

We are in no hurry, I just wanted to make sure it isn't forgotten during the switch to github.

@vstinner
Copy link
Owner

Your patch looks wrong: I see waitExit() in the traceback. The purpose of the function is to wait for the completion of the process, the exception should be handled here.

@pavlix
Copy link
Collaborator Author

pavlix commented Oct 12, 2016

@Haypo Just to make sure, “handled here” means handled inside the waitExit() function, i.e. waitExit() should return successfully whether the process exists or not?

@vstinner
Copy link
Owner

The cont() exception should be catched in waitExit().

@pavlix pavlix self-assigned this Oct 12, 2016
pavlix added a commit to crossdistro/network-testing that referenced this pull request Oct 27, 2016
    Traceback (most recent call last):
      File "./test-client-server", line 5, in <module>
        main()
      File "/home/pavlix/oss/network-testing/network_testing/client_server.py", line 55, in main
        suite.run()
      File "/home/pavlix/oss/network-testing/network_testing/test_suite.py", line 431, in run
        testcase.run()
      File "/home/pavlix/oss/network-testing/network_testing/test_suite.py", line 391, in run
        scenario.run()
      File "/home/pavlix/oss/network-testing/network_testing/test_suite.py", line 172, in run
        debugger.quit()
      File "/home/pavlix/oss/network-testing/network_testing/debug.py", line 198, in quit
        super(SyscallDebugger, self).quit()
      File "/usr/lib64/python3.4/site-packages/ptrace/debugger/debugger.py", line 105, in quit
        process.terminate()
      File "/usr/lib64/python3.4/site-packages/ptrace/debugger/process.py", line 330, in terminate
        self.waitExit()
      File "/usr/lib64/python3.4/site-packages/ptrace/debugger/process.py", line 351, in waitExit
        self.cont(signum)
      File "/usr/lib64/python3.4/site-packages/ptrace/debugger/process.py", line 717, in cont
        ptrace_cont(self.pid, signum)
      File "/usr/lib64/python3.4/site-packages/ptrace/binding/func.py", line 212, in ptrace_cont
        ptrace(PTRACE_CONT, pid, 0, signum)
      File "/usr/lib64/python3.4/site-packages/ptrace/binding/func.py", line 148, in ptrace
        raise PtraceError(message, errno=errno, pid=pid)
    ptrace.error.PtraceError: ptrace(cmd=7, pid=12894, 0, 133) error #3: No such process

Related: vstinner/python-ptrace#2
@vstinner
Copy link
Owner

I don't maintain this project anymore, I'm looking for a new maintainer.

Base automatically changed from master to main March 17, 2021 20:14
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

Successfully merging this pull request may close these issues.

2 participants