← Back to Pull requests

acme: refactor #19669

Merged
hgl merged 10 files (124 lines) on Oct 24, 2022 10:53 UTC
View on GitHub
hgl hgl commented on Oct 22, 2022 05:25 UTC
Author

  • Move notifying logic out of acme hooks

  • Prevent concurrent running of acme get

  • Use procd instead of hotplug to reload services (leaving hotplug for user scripts only)

  • Fix a bug where switching from staging to production didn't trigger the renew event
  • Signed-off-by: Glen Huang <i@glenhuang.com>

    Maintainer: @tohojo

    Description:

    Using hotplug to reload a service can inadvertently restarting it if it was stopped, as pointed out by @ptpt52.

    This PR make services use procd instead, which is how it should be properly done IMO. It also moves the actual notifying logic out of hooks, since they really shouldn't be concerned about how to actually do that.

    @tohojo, if you think the design is good I will change other related services too.

    Diff: 124 lines (+82 / -42) across 10 files Reviewer: tohojo Review duration: 3208m
    All Vouch review confidence checks passed
    Residual risk 0.12 = Change Risk (0.45) × (1 − Review Confidence (0.74)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.45 · 124 lines diff across 10 files
    0.45
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.50 · 5 substantive comment(s)
    0.50
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 50%
    74%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.289
    Real PR Conversation Timeline
    9 items
    tohojo tohojo commented on code on Oct 22, 2022 11:41 UTC
    Code Review
    net/acme-common/files/acme.sh:1
    @@ -128,11 +134,16 @@ fi
     
     case $1 in
     get)
    +	if [ -e "$run_dir"/lock ]; then
    +		log err "Another ACME instance is already running."
    +		exit 1
    +	fi
    +	touch "$run_dir/lock"
    +	trap cleanup EXIT

    This is racy; two processes could run the check at the same time and both end up continuing. You'll have to use an atomic operation to actually create the lock; for shell scripts that's usually mkdir. See this example from sqm-scripts for how to do it right:

    https://github.com/tohojo/sqm-scripts/blob/master/src/run-openwrt.sh#L80-L103

    tohojo tohojo requested changes on Oct 22, 2022 11:42 UTC
    Changes Requested Reviewer

    General refactoring is OK by me; however, please split each change out into a separate commit, with a commit message explaining the problem it's fixing, and how it's being fixed.

    Also, the locking is racy, see below...

    hgl hgl commented on code on Oct 22, 2022 14:22 UTC
    Code Review
    net/acme-common/files/acme.sh:1
    @@ -128,11 +134,16 @@ fi
     
     case $1 in
     get)
    +	if [ -e "$run_dir"/lock ]; then
    +		log err "Another ACME instance is already running."
    +		exit 1
    +	fi
    +	touch "$run_dir/lock"
    +	trap cleanup EXIT

    Fixed. I decided to use flock. Seems it's designed specifically for this use case.

    hgl hgl commented on Oct 22, 2022 14:23 UTC
    Author

    Updated as requested.

    tohojo tohojo commented on code on Oct 23, 2022 15:40 UTC
    Code Review
    net/acme-common/files/acme.sh:1
    @@ -128,11 +134,16 @@ fi
     
     case $1 in
     get)
    +	if [ -e "$run_dir"/lock ]; then
    +		log err "Another ACME instance is already running."
    +		exit 1
    +	fi
    +	touch "$run_dir/lock"
    +	trap cleanup EXIT

    I'm pretty sure this doesn't work the way you think it does; how did you test it?

    hgl hgl commented on code on Oct 24, 2022 02:54 UTC
    Code Review
    net/acme-common/files/acme.sh:1
    @@ -128,11 +134,16 @@ fi
     
     case $1 in
     get)
    +	if [ -e "$run_dir"/lock ]; then
    +		log err "Another ACME instance is already running."
    +		exit 1
    +	fi
    +	touch "$run_dir/lock"
    +	trap cleanup EXIT

    Sorry, I tested it in a small test script, but when tried to expand it in the real script, I got it wrong. It should be fixed.

    I also fixed one more bug during testing, and took the liberty to add support for a new option. Let me know what you think.

    tohojo tohojo commented on code on Oct 24, 2022 10:53 UTC
    Code Review
    net/acme-common/files/acme.sh:1
    @@ -128,11 +134,16 @@ fi
     
     case $1 in
     get)
    +	if [ -e "$run_dir"/lock ]; then
    +		log err "Another ACME instance is already running."
    +		exit 1
    +	fi
    +	touch "$run_dir/lock"
    +	trap cleanup EXIT

    Yeah, that's better!

    tohojo tohojo approved these changes on Oct 24, 2022 10:53 UTC
    Approved Reviewer

    Approved these changes.

    Reviewers
    Assignees
    hgl hgl
    Labels
    risk: low confidence: 74.3% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 45.1% (MEDIUM) · Higher = larger blast radius
    45.1%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 74.3% · Lower = rushed or shallow review
    74.3%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 11.6% · Safe to merge
    11.6%