Skip to content

Add more timeouts#69

Merged
dragonfire1119 merged 5 commits intomasterfrom
add-more-timeouts
Nov 28, 2025
Merged

Add more timeouts#69
dragonfire1119 merged 5 commits intomasterfrom
add-more-timeouts

Conversation

@dragonfire1119
Copy link
Contributor

This pull request improves the reliability of the CasaOS Docker Version Fix scripts by adding robust handling for potential hangs in dpkg -l commands, which can occur if the package database is locked. The changes ensure that any calls to dpkg -l are wrapped with a timeout, preventing the scripts from hanging indefinitely. Additionally, the test suite is enhanced to verify this behavior with a dedicated test for dpkg hangs.

Robust handling for dpkg hangs:

  • All instances of dpkg -l in run.sh are now wrapped with timeout 10 to prevent the script from hanging if the package database is locked. This applies to displaying Docker package versions, checking installed packages, and removing Docker-related packages. [1] [2] [3] [4] [5] [6]

Test suite enhancements:

  • A new test, test_dpkg_hang, is added to test-script.sh to simulate and verify handling of a hanging dpkg -l command using a mock dpkg binary and timeout logic.
  • The usage instructions and bug fix test summary are updated to include the new test-dpkg command and results. [1] [2] [3] [4] [5] [6] [7] [8] [9] [10]

Other improvements:

  • The script version string is updated from 2025.11.0 to 2025.11.1 in all relevant output locations for clarity. [1] [2]

These changes make the CasaOS Docker Version Fix scripts more robust and easier to test, especially in environments where package database locks are common.

Updated run.sh to use 'timeout' for all dpkg -l queries to prevent script hangs if the dpkg database is locked. Enhanced test-script.sh with a new test_dpkg_hang function and integrated it into the bug fix test suite to verify proper timeout handling for dpkg database hangs.
Bump displayed version in casaos-fix-docker-api-version/run.sh from 2025.11.0 to 2025.11.1 for consistency across script output and help messages.
@coderabbitai
Copy link

coderabbitai bot commented Nov 27, 2025

Summary by CodeRabbit

  • Bug Fixes

    • Added protection against package manager hangs by implementing timeouts on package-related queries.
  • Tests

    • Expanded test suite to verify handling of package manager database hang scenarios.

✏️ Tip: You can customize this high-level summary in your review settings.

Walkthrough

Bash scripts: bumped displayed version to 2025.11.1; added timeout 10 wrappers around dpkg/containerd/package-version queries; added test_dpkg_hang() and wired it into help/dispatcher, expanding the bug-fix test suite from 6 to 7 tests.

Changes

Cohort / File(s) Summary
Version update & timeout protection
casaos-fix-docker-api-version/run.sh
Updated visible version strings to 2025.11.1. Replaced direct dpkg -l and related package/version invocations with timeout 10 prefixed calls (including containerd/package lookups) to bound potential hangs; preserved existing output paths.
Test suite expansion & dispatcher/help updates
casaos-fix-docker-api-version/test-script.sh
Added test_dpkg_hang() which mocks a hanging dpkg to verify timeout behavior, integrates mocked docker for command checks, and assesses display_versions under mock. Updated help/usage, command dispatcher (aliases `test-dpkg

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

  • Verify each timeout 10 usage handles exit codes and timeouts consistently where results are parsed.
  • Review test_dpkg_hang() for safe mocking: ensure temporary PATH overrides or function stubs are localized and cleaned up.
  • Confirm all help text and "Test X of Y" labels were updated comprehensively.

Poem

🐰 I nudge the scripts with twitchy nose,
A timeout stitch where dpkg froze,
Seven checks now hop and play,
No stuck installs to spoil the day,
I nibble code and bound away.

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title 'Add more timeouts' directly describes the main change of wrapping dpkg calls with timeout 10, which is the primary improvement across both modified files.
Description check ✅ Passed The description comprehensively explains the purpose and scope of the changes, including timeout handling for dpkg commands and the new test suite enhancements.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch add-more-timeouts

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

Cache: Disabled due to Reviews > Disable Cache setting

Knowledge base: Disabled due to data retention organization setting

📥 Commits

Reviewing files that changed from the base of the PR and between 4a743cf and f2979a0.

📒 Files selected for processing (1)
  • casaos-fix-docker-api-version/test-script.sh (11 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
casaos-fix-docker-api-version/test-script.sh (1)
casaos-fix-docker-api-version/run.sh (1)
  • print_info (28-59)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: test-fix-script
  • GitHub Check: test-fix-script
🔇 Additional comments (6)
casaos-fix-docker-api-version/test-script.sh (6)

1293-1294: Help text properly integrated.

The new test-dpkg entry is correctly added to both the command list and example usage sections, following existing conventions.


1604-1641: SC2155 properly addressed via upfront variable declaration.

Variables are pre-declared as locals (line 1605) and assigned on separate lines (1608, 1621, 1629, 1633–1637), correctly avoiding the masking of return values flagged in past reviews.


1607-1660: Timeout test logic is sound and follows established patterns.

Mock dpkg sleeps 20 seconds with a 10-second timeout, ensuring reliable timeout detection (exit code 124). The explicit path invocation (line 1634) is more robust than PATH manipulation alone. Duration bounds and exit code checks are consistent with similar tests like test_snap_hang.


1662-1740: Function behavior test properly exercises timeout in display_versions context.

The nested test script correctly captures the mock directory via variable expansion in the unquoted heredoc (line 1667). The dpkg function override (lines 1677–1679) reliably invokes the mock. Mock docker creation (lines 1704–1710) ensures command -v docker succeeds. Awk field references (\$2, \$3 at line 1690) are correctly escaped for the heredoc. Timeout detection via fallback message (lines 1733–1740) validates graceful handling.


1750-1870: Bug fix test suite properly expanded to 7 tests with consistent labeling.

Test counters updated throughout (lines 1767, 1783, 1799, 1815, 1831, 1847), and the new dpkg hang test section (lines 1856–1870) follows the established pattern for test execution, result tracking, and messaging. Help text (line 1760) correctly describes the expanded suite.


1936-1938: Command dispatcher correctly routes test-dpkg variants to test_dpkg_hang.

Case statement includes all three expected aliases (test-dpkg, dpkg, test-dpkg-hang), consistent with other test function dispatchers and providing flexible command entry points.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

Cache: Disabled due to Reviews > Disable Cache setting

Knowledge base: Disabled due to data retention organization setting

📥 Commits

Reviewing files that changed from the base of the PR and between 72ac7a3 and 7067890.

📒 Files selected for processing (2)
  • casaos-fix-docker-api-version/run.sh (8 hunks)
  • casaos-fix-docker-api-version/test-script.sh (11 hunks)
🧰 Additional context used
🧬 Code graph analysis (2)
casaos-fix-docker-api-version/run.sh (1)
casaos-fix-docker-api-version/test-script.sh (2)
  • apply_docker_api_override (193-260)
  • remove_docker_api_override (263-293)
casaos-fix-docker-api-version/test-script.sh (1)
casaos-fix-docker-api-version/run.sh (1)
  • print_info (28-59)
🪛 Shellcheck (0.11.0)
casaos-fix-docker-api-version/run.sh

[warning] 321-321: Declare and assign separately to avoid masking return values.

(SC2155)

casaos-fix-docker-api-version/test-script.sh

[warning] 1624-1624: Declare and assign separately to avoid masking return values.

(SC2155)


[warning] 1627-1627: Declare and assign separately to avoid masking return values.

(SC2155)

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: test-fix-script
  • GitHub Check: test-fix-script
🔇 Additional comments (9)
casaos-fix-docker-api-version/run.sh (5)

62-62: Version bump consistently applied across headers and outputs.

The version string updates from 2025.11.0 to 2025.11.1 are correctly applied in all script headers and informational messages. No issues detected.

Also applies to: 1575-1575, 1583-1583, 1591-1591


93-93: Timeout wrapping applied to dpkg -l query in display_versions().

The timeout 10 wrapper prevents hangs when the package database is locked. The fallback error message provides appropriate feedback. Implementation is correct.


965-965: Timeout correctly applied to dpkg check in remove_standalone_docker_compose().

The timeout 10 wrapper prevents hangs when querying installed docker-compose packages. Error handling with the fallback path is appropriate.


1088-1088: Timeout wrapping applied to dpkg check in downgrade_docker().

The timeout prevents hangs before removing existing Docker packages. The conditional flow correctly handles both timeout and non-timeout scenarios.


2024-2024: Timeout wrapping consistently applied to final dpkg output queries.

Both the summary output and diagnostic information sections correctly wrap dpkg -l with timeout 10. Error messages provide appropriate user-facing feedback when timeouts occur.

Also applies to: 2080-2080

casaos-fix-docker-api-version/test-script.sh (4)

1597-1732: New test_dpkg_hang() function comprehensively validates dpkg timeout behavior.

The test function follows the established pattern from other hang tests (test_snap_hang, test_casaos_hang) and correctly verifies:

  • Timeout command exits with code 124 within expected timeframe (~10s)
  • Mock dpkg hang is properly simulated
  • display_versions()-like behavior handles timeout gracefully
  • Fallback error message is displayed when timeout occurs

The implementation is thorough and well-structured.


1294-1294: Help text updated to include new test-dpkg command.

The usage documentation correctly adds the new test-dpkg command description at lines 1294 and 1320, maintaining consistency with other similar commands and providing clear instructions.

Also applies to: 1320-1320


1920-1922: Command dispatcher correctly integrated for test-dpkg aliases.

The case statement at lines 1920-1922 properly handles the test-dpkg|dpkg|test-dpkg-hang command aliases and invokes test_dpkg_hang(), maintaining consistency with other test command patterns.


1751-1751: Test counter and sequencing updated correctly in test_all_bugfixes().

The test numbering has been updated from "6 of 6" to "7 of 7" consistently throughout the test_all_bugfixes() function:

  • Line 1751: Test 1 of 7 (GPG)
  • Line 1767: Test 2 of 7 (GPG download)
  • Line 1783: Test 3 of 7 (Snap)
  • Line 1799: Test 4 of 7 (netns)
  • Line 1815: Test 5 of 7 (daemon)
  • Line 1831: Test 6 of 7 (CasaOS)
  • Line 1847: Test 7 of 7 (dpkg)

The new test is properly integrated into the test suite with correct sequencing.

Also applies to: 1767-1767, 1783-1783, 1799-1799, 1815-1815, 1831-1831, 1847-1847

Updated variable assignment in run.sh and test-script.sh to use separate declaration and assignment lines, improving POSIX shell compatibility and readability.
Refactored test_dpkg_hang to declare local variables upfront, avoid SC2155 issues, and use explicit paths for the mock dpkg command. Updated PATH handling and hash table clearing to ensure the mock is used, and improved the test script to override dpkg for more reliable testing.
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (1)
casaos-fix-docker-api-version/test-script.sh (1)

1597-1748: LGTM: Well-structured dpkg hang test with one SC2155 style fix needed.

The new test_dpkg_hang() function follows established patterns from test_snap_hang() and test_casaos_hang(), correctly simulates dpkg database locks with a mock binary, and verifies timeout behavior within expected bounds. The upfront variable declarations at line 1605 properly address SC2155 concerns, separating declarations from assignments throughout the function.

One minor refinement for consistency: line 1666 should not re-declare test_script as local since it was already declared at function scope on line 1605. This combines declaration + assignment, which contradicts the SC2155 pattern applied earlier in the function.

Apply this diff to line 1666:

-  # Extract just the function from run.sh - but use explicit mock path
-  local test_script="/tmp/test-dpkg-func-$$.sh"
+  # Extract just the function from run.sh - but use explicit mock path
+  test_script="/tmp/test-dpkg-func-$$.sh"
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

Cache: Disabled due to Reviews > Disable Cache setting

Knowledge base: Disabled due to data retention organization setting

📥 Commits

Reviewing files that changed from the base of the PR and between 81452f6 and 4a743cf.

📒 Files selected for processing (1)
  • casaos-fix-docker-api-version/test-script.sh (11 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
casaos-fix-docker-api-version/test-script.sh (1)
casaos-fix-docker-api-version/run.sh (1)
  • print_info (28-59)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: test-fix-script
  • GitHub Check: test-fix-script
🔇 Additional comments (2)
casaos-fix-docker-api-version/test-script.sh (2)

1287-1331: Usage and help text updated correctly for new test command.

Lines 1294 and 1320 add test-dpkg documentation to both the main help output and usage examples, maintaining consistency with existing bug-fix test descriptions.


1750-1887: Test numbering and dispatcher integration correct.

All references to "Test X of 6" have been updated to "Test X of 7" (lines 1760, 1767, 1783, 1799, 1815, 1831, 1847, 1863), and the new dpkg test is properly wired into test_all_bugfixes() as test 7 of 7. The main function dispatcher (lines 1936-1938) correctly routes the three command aliases (test-dpkg, dpkg, test-dpkg-hang) to test_dpkg_hang.

The 'local' keyword was removed from the 'test_script' variable declaration in test-script.sh to ensure compatibility and correct scoping outside of functions.
@dragonfire1119 dragonfire1119 merged commit ac0cbd0 into master Nov 28, 2025
3 checks passed
@dragonfire1119 dragonfire1119 deleted the add-more-timeouts branch November 28, 2025 15:42
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