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

Fix stealth exceptions and blocking select() in daemonize() #81064

Merged
merged 2 commits into from
Jul 17, 2023

Conversation

vaygr
Copy link
Contributor

@vaygr vaygr commented Jun 14, 2023

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 to module_utils.service in #21256 with a couple of issues that are not reproducible with the code from the now-deprecated service 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:

  1. Padding bug on L220: local variable 'data' referenced before assignment
  2. Type bugs on L220 and L251: 'bytes' object has no attribute 'encode'
  3. The biggest logical one on L214 is two-fold:
    1. p.poll() should be replaced with p.poll() is None as it was in the deprecated service module since as per #subprocess.Popen.poll it can return 0, 1, 2, etc. (any return code) as well as None while the process hasn't terminated.
    2. Missing else: break that's also present in the deprecated service module: because we have a 2-process communication (parent, child) the condition on L214 is never satisfied, and the parent's select() blocks indefinitely waiting for the child on L246 (#select.select). By adding else: break we exit the loop when the process started by the child exits.

cc @bcoca

ISSUE TYPE
  • Bugfix Pull Request
COMPONENT NAME

module_utils.service

ADDITIONAL INFORMATION

Relevant code from modules.service: service.py#L301-L335

@ansibot ansibot added affects_2.16 bug This issue/PR relates to a bug. needs_triage Needs a first human triage before being processed. labels Jun 14, 2023
@ansibot ansibot added the needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. label Jun 15, 2023
@bcoca bcoca removed the needs_triage Needs a first human triage before being processed. label Jun 15, 2023
sivel
sivel previously requested changes Jun 15, 2023
Copy link
Member

@sivel sivel left a 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.

@vaygr
Copy link
Contributor Author

vaygr commented Jun 15, 2023

@sivel Seems I missed that the sysvinit module still uses it if daemonize option is specified. It doesn't seem it's used broadly though, based on my GitHub search.

Do you want me to deprecate that option as well or there are no plans to take care of this atm?

@sivel
Copy link
Member

sivel commented Jun 15, 2023

@vaygr give me a little while to validate what you just said. We may have missed the sysvinit module also.

@vaygr
Copy link
Contributor Author

vaygr commented Jun 15, 2023

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

@sivel
Copy link
Member

sivel commented Jun 15, 2023

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.

@sivel sivel dismissed their stale review June 15, 2023 19:56

Errant evaluation

@ansibot ansibot removed the needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. label Jun 15, 2023
@ansibot ansibot added the stale_ci This PR has been tested by CI more than one week ago. Close and re-open this PR to get it retested. label Jun 23, 2023
@vaygr
Copy link
Contributor Author

vaygr commented Jul 16, 2023

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.

@bcoca bcoca merged commit 894c339 into ansible:devel Jul 17, 2023
84 checks passed
@vaygr vaygr deleted the daemonize-fixes branch July 18, 2023 15:07
@ansible ansible locked and limited conversation to collaborators Jul 24, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
affects_2.16 bug This issue/PR relates to a bug. stale_ci This PR has been tested by CI more than one week ago. Close and re-open this PR to get it retested.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants