Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 672540 - sys-apps/portage: AsyncioEventLoop exception handler does not allow exit with Ctrl-C, SIGKILL required
Summary: sys-apps/portage: AsyncioEventLoop exception handler does not allow exit with...
Status: RESOLVED FIXED
Alias: None
Product: Portage Development
Classification: Unclassified
Component: Core - Interface (emerge) (show other bugs)
Hardware: All Linux
: Normal normal
Assignee: Portage team
URL:
Whiteboard:
Keywords: InVCS
Depends on:
Blocks: 683434
  Show dependency tree
 
Reported: 2018-12-05 01:25 UTC by Zac Medico
Modified: 2019-06-23 18:29 UTC (History)
0 users

See Also:
Package list:
Runtime testing required: ---


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Zac Medico gentoo-dev 2018-12-05 01:25:53 UTC
For example, when /var/tmp/portage runs out of space and bug 451158 is triggered, it stops like this and the user has to use SIGKILL to end the process:

> >>> Jobs: 1 of 22 complete, 3 running               Load avg: 15.6, 11.8, 10.4Exception in callback PipeLogger._output_handler(18)                                                                                
> handle: <Handle PipeLogger._output_handler(18)>
> Traceback (most recent call last):
>   File "/usr/lib64/python3.6/asyncio/events.py", line 145, in _run
>     self._callback(*self._args)
>   File "/usr/lib64/python3.6/site-packages/portage/util/_async/PipeLogger.py", line 124, in _output_handler                                                                                                       
>     log_file.flush()
> OSError: [Errno 28] No space left on device
> --Return--
> > /usr/lib64/python3.6/site-packages/portage/util/_eventloop/asyncio_event_loop.py(76)_internal_caller_exception_handler()->None                                                                                  
> -> pdb.set_trace()
> (Pdb)
We can enable Ctrl-C in this situation, like this:

> diff --git a/lib/portage/util/_eventloop/asyncio_event_loop.py b/lib/portage/util/_eventloop/asyncio_event_loop.py
> index ea0e03b23..50839ad26 100644
> --- a/lib/portage/util/_eventloop/asyncio_event_loop.py
> +++ b/lib/portage/util/_eventloop/asyncio_event_loop.py
> @@ -73,6 +73,7 @@ class AsyncioEventLoop(_AbstractEventLoop):
>                         # aid in diagnosis of the problem. If there's no tty, then
>                         # exit immediately.
>                         if all(s.isatty() for s in (sys.stdout, sys.stderr, sys.stdin)):
> +                               signal.signal(signal.SIGINT, signal.SIG_DFL)
>                                 pdb.set_trace()
>                         else:
>                                 # Normally emerge will wait for all coroutines to complete
Comment 1 Zac Medico gentoo-dev 2018-12-05 18:35:33 UTC
Maybe Scheduler should override the AsyncioEventLoop exception handler when it overrides the SIGINT/SIGTERM handlers.
Comment 2 Zac Medico gentoo-dev 2019-04-15 23:29:03 UTC
Maybe Scheduler could also use the asyncio loop.add_signal_handler API instead of using the signal module directly:

https://docs.python.org/3/library/asyncio-eventloop.html#asyncio.loop.add_signal_handler
Comment 3 Larry the Git Cow gentoo-dev 2019-04-16 02:07:09 UTC
The bug has been referenced in the following commit(s):

https://gitweb.gentoo.org/proj/portage.git/commit/?id=ee1f6ff69887dfa02d5c3a3ab3d61163fa504d15

commit ee1f6ff69887dfa02d5c3a3ab3d61163fa504d15
Author:     Zac Medico <zmedico@gentoo.org>
AuthorDate: 2019-04-16 01:33:29 +0000
Commit:     Zac Medico <zmedico@gentoo.org>
CommitDate: 2019-04-16 01:40:29 +0000

    AsyncioEventLoop: enable SIGINT in exception handler (bug 672540)
    
    Before the exception handler invokes the pdb shell, enable SIGINT so
    that the user can exit with Control-C (otherwise SIGKILL is needed).
    
    Bug: https://bugs.gentoo.org/672540
    Signed-off-by: Zac Medico <zmedico@gentoo.org>

 lib/portage/util/_eventloop/asyncio_event_loop.py | 5 +++++
 1 file changed, 5 insertions(+)
Comment 4 Zac Medico gentoo-dev 2019-04-16 02:21:08 UTC
(In reply to Zac Medico from comment #2)
> Maybe Scheduler could also use the asyncio loop.add_signal_handler API
> instead of using the signal module directly:
> 
> https://docs.python.org/3/library/asyncio-eventloop.html#asyncio.loop.
> add_signal_handler

This wouldn't be useful in the context of this bug since event loop signal handlers are useless when the loop is suspended (same problem as Scheduler's existing signal handler which relies on the event loop to ultimately trigger exit).