The AbstractPollTask._unregister_if_appropriate method calls self.wait() before the process exit status has become available, which for subclasses of SubProcess will ultimately triggering recursion in the SubProcess._waitpid_loop method. This is only a problem for EbuildMetadataPhase, since it's the only subclass of SubProcess that calls _unregister_if_appropriate.
The bug has been referenced in the following commit(s): https://gitweb.gentoo.org/proj/portage.git/commit/?id=c5ab0696cec1f0f020d2d8ad416f9b1444a467de commit c5ab0696cec1f0f020d2d8ad416f9b1444a467de Author: Zac Medico <zmedico@gentoo.org> AuthorDate: 2018-04-22 18:16:55 +0000 Commit: Zac Medico <zmedico@gentoo.org> CommitDate: 2018-04-22 18:16:55 +0000 SubProcess: fix _unregister_if_appropriate event loop recursion (bug 614104) Override the AbstractPollTask._unregister_if_appropriate method to avoid event loop recursion when the pid exit status is not yet available, by calling self._async_waitpid() instead of self.wait(). Also make _async_waitpid fallback to _async_wait if the pid exit status happens to be available already. Bug: https://bugs.gentoo.org/614104 pym/_emerge/SubProcess.py | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-)}
Fixed in portage-2.3.40-r1.