Add step-level timeout to prevent infinite execution#140
Merged
Conversation
Code Metrics Report
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%)
Reported by octocov |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
When actions hang or take too long to complete, jobs can run indefinitely, causing:
This was particularly problematic for:
Solution
Implemented step-level timeout functionality at the action execution layer:
Implementation Details
Added
Timeoutfield to Step struct (step.go:24)Interval(supports YAML duration format like "5m", "30s")Defined
DefaultStepTimeoutconstant (step.go:14-16)Timeout enforcement in
executeSingleAction(step.go:108-139)context.WithTimeoutfor proper timeout handlingFeatures
```yaml
steps:
uses: http
timeout: 30s
```
Testing
Added comprehensive unit tests (step_test.go:1289-1447):
TestStep_executeSingleAction_DefaultTimeout- Default 5min timeoutTestStep_executeSingleAction_CustomTimeout- Custom timeout enforcementTestStep_executeSingleAction_CompletesBeforeTimeout- Normal completionTestStep_executeActionWithRetry_Timeout- Timeout with retry logicTestStep_DefaultStepTimeout_Value- Constant value verificationAll tests pass:
Example Usage
```yaml
examples/timeout-literal.yml
jobs:
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.