Skip to content

Add step-level timeout to prevent infinite execution#140

Merged
linyows merged 3 commits intomainfrom
add-step-timeout
Jan 10, 2026
Merged

Add step-level timeout to prevent infinite execution#140
linyows merged 3 commits intomainfrom
add-step-timeout

Conversation

@linyows
Copy link
Owner

@linyows linyows commented Jan 10, 2026

Problem

When actions hang or take too long to complete, jobs can run indefinitely, causing:

  • Workflows that never complete
  • Dependent jobs waiting forever
  • CI/CD pipelines getting stuck

This was particularly problematic for:

  • HTTP actions without timeout (could hang forever)
  • Background shell executions (timeout is intentionally ignored)
  • Actions with retry logic (each retry could hang)

Solution

Implemented step-level timeout functionality at the action execution layer:

Implementation Details

  1. Added Timeout field to Step struct (step.go:24)

    • Type: Interval (supports YAML duration format like "5m", "30s")
    • Optional field with omitempty
  2. Defined DefaultStepTimeout constant (step.go:14-16)

    • Default: 5 minutes
    • Applied when no timeout is specified
  3. Timeout enforcement in executeSingleAction (step.go:108-139)

    • Uses context.WithTimeout for proper timeout handling
    • Action runs in goroutine with timeout monitoring
    • Returns timeout error when exceeded

Features

  • Default timeout: All actions default to 5 minutes
  • Custom timeout: Can be overridden per step in YAML:
    ```yaml
    steps:
    • name: Custom timeout step
      uses: http
      timeout: 30s
      ```
  • Works with retry: Each retry attempt respects the timeout
  • Universal coverage: Applies to all actions (http, shell, db, etc.)

Testing

Added comprehensive unit tests (step_test.go:1289-1447):

  1. TestStep_executeSingleAction_DefaultTimeout - Default 5min timeout
  2. TestStep_executeSingleAction_CustomTimeout - Custom timeout enforcement
  3. TestStep_executeSingleAction_CompletesBeforeTimeout - Normal completion
  4. TestStep_executeActionWithRetry_Timeout - Timeout with retry logic
  5. TestStep_DefaultStepTimeout_Value - Constant value verification

All tests pass:

  • New timeout tests: 5/5 ✅
  • Existing step tests: All passing ✅
  • Full package tests: All passing ✅

Example Usage

```yaml

examples/timeout-literal.yml

jobs:

  • name: Test timeouts
    steps:
    • name: Default 5min timeout
      uses: http
      with:
      url: https://example.com

    • name: Custom 10s timeout
      uses: http
      timeout: 10s
      with:
      url: https://slow-api.example.com

    • name: Timeout with retry
      uses: http
      timeout: 5s
      retry:
      max_attempts: 3
      interval: 1s
      ```

Impact

This change prevents infinite execution scenarios and ensures workflows complete in a reasonable time, improving reliability for CI/CD pipelines and monitoring systems.

@github-actions
Copy link

Code Metrics Report

main (9e5620b) #140 (c549357) +/-
Coverage 47.8% 48.2% +0.3%
Code to Test Ratio 1:1.1 1:1.1 +0.0
Test Execution Time 18s 19s +1s
Details
  |                     | main (9e5620b) | #140 (c549357) |  +/-  |
  |---------------------|----------------|----------------|-------|
+ | Coverage            |          47.8% |          48.2% | +0.3% |
  |   Files             |             52 |             52 |     0 |
  |   Lines             |           5235 |           5244 |    +9 |
+ |   Covered           |           2507 |           2530 |   +23 |
+ | Code to Test Ratio  |          1:1.1 |          1:1.1 |  +0.0 |
  |   Code              |          10542 |          10564 |   +22 |
+ |   Test              |          11735 |          11856 |  +121 |
- | Test Execution Time |            18s |            19s |   +1s |

Code coverage of files in pull request scope (64.1% → 68.3%)

Files Coverage +/- Status
mail/mock_server.go 72.0% -1.1% affected
step.go 67.3% +5.9% modified

Reported by octocov

@linyows linyows self-assigned this Jan 10, 2026
@linyows linyows merged commit 2b97adc into main Jan 10, 2026
6 checks passed
@linyows linyows deleted the add-step-timeout branch January 10, 2026 13:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant