Skip to content

healthcheck.sh exits prematurely due to ((var++)) under set -e #302

@nathanschram

Description

Problem

scripts/healthcheck.sh aborts after the first pass or fail call, reporting only one check instead of all five.

$ scripts/healthcheck.sh --version 0.35.1rc5
Checking service: untether.service
---
OK: service is active
$ echo $?
1

Root cause

The script runs under set -euo pipefail. Both counter helpers use post-increment arithmetic:

pass() { echo "OK: $1"; ((CHECKS_PASSED++)); }
fail() { echo "FAIL: $1"; ((CHECKS_FAILED++)); }

((expr)) returns a non-zero exit status when expr evaluates to 0. Post-increment returns the old value, so the first call (when the counter is 0) exits 1 and set -e terminates the script before any further checks run.

Fix

Use explicit assignment, which always exits 0:

pass() { echo "OK: $1"; CHECKS_PASSED=$((CHECKS_PASSED + 1)); }
fail() { echo "FAIL: $1"; CHECKS_FAILED=$((CHECKS_FAILED + 1)); }

Impact

  • Post-deploy healthchecks have been silently skipping the version/errors/Bot-API checks since the script was added.
  • Exit code 1 was masking the missing checks — deploy scripts using the healthcheck would have flagged successful deploys as failed.

Affected files

  • scripts/healthcheck.sh (lines 26–27)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions