Skip to content

Conversation

@iav
Copy link
Contributor

@iav iav commented Jan 16, 2026

Summary

  • Add user feedback when memoize cache lock is held by another process
  • Add configurable timeout via MEMOIZE_FLOCK_MAX_WAIT environment variable
  • Prevent builds from hanging indefinitely due to stale Docker containers

Problem

When a build is interrupted (e.g., via Ctrl+C or system crash), Docker containers may continue running and hold flock locks on memoize cache files in cache/memoize/. Subsequent builds would hang indefinitely at the "artifact [ kernel :: kernel() ]" stage without any feedback to the user.

Solution

Instead of blocking indefinitely on flock, this change:

  1. First tries non-blocking flock -n - acquires immediately if available
  2. If lock is busy, informs the user with actionable message
  3. Waits with periodic status messages (every 10s by default)
  4. Optionally times out after configurable duration
  5. Suggests checking for stale containers: docker ps -a | grep armbian

New Configuration Variables

Variable Default Description
MEMOIZE_FLOCK_WAIT_INTERVAL 10 Seconds between status messages while waiting
MEMOIZE_FLOCK_MAX_WAIT 0 Maximum wait time in seconds (0 = infinite, for backward compatibility)

Test plan

  • Build with no other processes running - should work as before
  • Start a build, interrupt it, start another - should show waiting message
  • Set MEMOIZE_FLOCK_MAX_WAIT=30 and test timeout behavior
  • Verify Ctrl+C works during lock wait

🤖 Generated with Claude Code

@iav iav requested review from a team and igorpecovnik as code owners January 16, 2026 20:18
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 16, 2026

📝 Walkthrough

Walkthrough

Modifies the memoization cache file locking mechanism in a single script to replace immediate blocking locks with non-blocking, timed locks featuring configurable retry intervals and maximum wait durations, with periodic status alerts during the waiting period.

Changes

Cohort / File(s) Summary
Memoization Locking Enhancement
lib/functions/general/memoize-cached.sh
Changed from blocking flock to non-blocking flock with retry loop and timeout logic. Added MEMOIZE_FLOCK_WAIT_INTERVAL (default 10s) and MEMOIZE_FLOCK_MAX_WAIT (default 0/infinite) configuration variables. Lock acquisition now emits progress alerts while waiting, failure alerts on timeout, and success alerts with total wait time.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Poem

🐰 A lock that waits with patience true,
No blocking here—we'll try anew!
With timed retries and friendly cheer,
The memoize cache holds files dear.
Progress whispers as we stand,
Till the lock is in our hand! 🔓

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: adding user feedback and configurable timeout for the flock mechanism in memoization, which matches the core objective of improving lock handling behavior.
Docstring Coverage ✅ Passed Docstring coverage is 90.91% which is sufficient. The required threshold is 80.00%.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Docstrings were successfully generated.

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.

@github-actions github-actions bot added 02 Milestone: First quarter release size/large PR with 250 lines or more Needs review Seeking for review Framework Framework components labels Jan 16, 2026
@iav iav marked this pull request as draft January 16, 2026 20:19
When the memoize cache lock is held by another process (e.g., a stale
Docker container from a previous interrupted build), the build would
hang indefinitely without any feedback to the user.

This change:
- First tries non-blocking flock, acquiring immediately if available
- If lock is busy, informs user and waits with periodic status messages
- Adds MEMOIZE_FLOCK_WAIT_INTERVAL (default 10s) for message frequency
- Adds MEMOIZE_FLOCK_MAX_WAIT (default 0=infinite) for optional timeout
- Allows user to interrupt with Ctrl+C
- Suggests checking for stale containers: docker ps -a | grep armbian

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <[email protected]>
@iav iav force-pushed the fix/memoize-flock-timeout branch from 2cd603a to a968504 Compare January 16, 2026 20:21
@github-actions github-actions bot added size/small PR with less then 50 lines and removed size/large PR with 250 lines or more labels Jan 16, 2026
@iav
Copy link
Contributor Author

iav commented Jan 16, 2026

@CodeRabbit review

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 16, 2026

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 16, 2026

Note

Docstrings generation - SUCCESS
Generated docstrings for this pull request at #9263

coderabbitai bot added a commit that referenced this pull request Jan 16, 2026
Docstrings generation was requested by @iav.

* #9262 (comment)

The following files were modified:

* `lib/functions/general/memoize-cached.sh`
@iav iav marked this pull request as ready for review January 17, 2026 03:39
@rpardini
Copy link
Member

While this is nice addition... I'd also like to understand how "When a build is interrupted..., Docker containers may continue running and hold flock locks on memoize cache" happens, and maybe handle it too (add a cleanup handler or such...)?

@iav
Copy link
Contributor Author

iav commented Jan 17, 2026

Docker containers may continue running and hold flock locks on memoize cache" happens, and maybe handle it too (add a cleanup handler or such...)?

I encounter this quite rarely, and it happens during multiple manual starts and manual interruptions of the build process. I decided to investigate the situation after my Armbian build suddenly and strangely froze twice within a week. I spent almost an hour trying to figure out what was going on. It was working just a moment ago, and now it gets to a certain point and just freezes, WTF!!! And I can't figure out how to fix it!

However, I don't think something like this could happen anywhere on runners. That is, I believe this situation could only arise with human intervention, and therefore, warning that person about what exactly happened is quite sufficient. Another reason not to automate the cleanup is that I don't know what else could cause such a blockage, so I don't want to break something I have no idea about.

Copy link
Member

@rpardini rpardini left a comment

Choose a reason for hiding this comment

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

Ok, this doesn't hurt, and unless MEMOIZE_FLOCK_MAX_WAIT is set, doesn't change anything.

Later, we could investigate why the hang further (probably on the remote call to obtain some version, we could call the memoized function with timeout ...) and maybe in this same spot add a cleanup handler (equivalent to using a bash trap).

@github-actions github-actions bot added the Ready to merge Reviewed, tested and ready for merge label Jan 17, 2026
@github-actions
Copy link
Contributor

✅ This PR has been reviewed and approved — all set for merge!

@github-actions github-actions bot removed the Needs review Seeking for review label Jan 17, 2026
@iav
Copy link
Contributor Author

iav commented Jan 17, 2026

If it turns out that long blockages are caused by something other than manual build interruptions, then this could be investigated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

02 Milestone: First quarter release Framework Framework components Ready to merge Reviewed, tested and ready for merge size/small PR with less then 50 lines

Development

Successfully merging this pull request may close these issues.

2 participants