-
Notifications
You must be signed in to change notification settings - Fork 23.7k
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
Fix stealth exceptions and blocking select() in daemonize() #81064
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We've decided to not accept these changes. As no current module uses this code, and we have no need for it in ansible-core, this should be pulled into the collection you need, updated to work as you expect, and separately we need to deprecate this and remove it from ansible/ansible.
@sivel Seems I missed that the Do you want me to deprecate that option as well or there are no plans to take care of this atm? |
@vaygr give me a little while to validate what you just said. We may have missed the |
Yeah, I'm thinking there could be valid use cases for this, even though rare: daemonize:
type: bool
description:
- Have the module daemonize as the service itself might not do so properly.
- This is useful with badly written init scripts or daemons, which
commonly manifests as the task hanging as it is still holding the
tty or the service dying when the task is over as the connection
closes the session.
default: no |
Ok, we did miss that module, not sure how, but thank you for bring it to my attention. I'm going to dismiss my review, and then it'll require an actual code review from the core team, which likely won't come from me. |
Hey @sivel @bcoca, I was wondering if somebody had a chance to take a look at it, as it's blocking ansible-collections/community.general#6618. |
SUMMARY
This came out of the debugging session from ansible-collections/community.general#6618 where a module must use
daemonize()
to work.daemonize()
was ported tomodule_utils.service
in #21256 with a couple of issues that are not reproducible with the code from the now-deprecatedservice
module. I couldn't find use of it alone in both ansible and community.general collection repos, so it seems it wasn't tested thoroughly afterwards.This PR fixes a few things:
local variable 'data' referenced before assignment
'bytes' object has no attribute 'encode'
p.poll()
should be replaced withp.poll() is None
as it was in the deprecatedservice
module since as per #subprocess.Popen.poll it can return0
,1
,2
, etc. (any return code) as well asNone
while the process hasn't terminated.else: break
that's also present in the deprecatedservice
module: because we have a 2-process communication (parent, child) the condition on L214 is never satisfied, and the parent'sselect()
blocks indefinitely waiting for the child on L246 (#select.select). By addingelse: break
we exit the loop when the process started by the child exits.cc @bcoca
ISSUE TYPE
COMPONENT NAME
module_utils.service
ADDITIONAL INFORMATION
Relevant code from
modules.service
: service.py#L301-L335