You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 528e699
Browse filesBrowse the repository at this point in the historyBrowse files
fix: prevent infinite ccusage process spawning with file-based locking
This commit addresses the critical issue where cc-statusline could cause
infinite spawning of ccusage processes, leading to system resource exhaustion.
Problem:
- Multiple ccusage processes spawned concurrently when statusline triggered rapidly
- CPU usage exceeded 300% with 30+ Node.js processes
- Memory consumption grew to 3+ GB
- Systems became unresponsive (affects Linux, macOS, Windows)
- Related to issue reported at ccusage/ccusage#459
Solution:
- Implemented file-based semaphore locking mechanism at /tmp/ccusage_statusline.lock
- Added PID tracking to detect and clean up stale locks
- Introduced 3-second timeout for ccusage execution
- Process existence checking using kill -0 (POSIX-compliant)
- Graceful fallback when lock is held (skip instead of queue)
Implementation details:
- Lock directory creation is atomic (mkdir is atomic on POSIX systems)
- PID file tracks lock owner for stale lock detection
- Supports timeout/gtimeout commands with fallback for compatibility
- Cross-platform compatible (Linux, macOS, BSD)
Testing performed:
- Verified prevention of concurrent executions with rapid calls
- Confirmed no process pile-up or resource leaks
- Tested lock cleanup for both normal and abnormal termination
- Validated on macOS; ready for community testing on Linux/Windows
This fix ensures only one ccusage process runs at a time, preventing the
cascade effect that was causing system instability.
Fixes the spawning issue without requiring changes to ccusage itself,
working with existing ccusage versions that support 'blocks --json'.
Copy file name to clipboardExpand all lines: CHANGELOG.md
+14Lines changed: 14 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,6 +5,20 @@ All notable changes to this project will be documented in this file.
5
5
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
6
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
8
+
## [1.2.3] - 2025-08-20
9
+
10
+
### Fixed
11
+
- 🔒 **Critical Process Spawning Fix** - Added file-based locking mechanism to prevent infinite ccusage process spawning
12
+
- ⚡ **Performance** - Implemented 3-second timeout for ccusage calls to prevent hanging
13
+
- 🛡️ **Stability** - Added PID tracking for stale lock detection and cleanup
14
+
- 🔧 **Cross-platform** - Multiple timeout strategies for Linux, macOS, and BSD compatibility
15
+
16
+
### Technical Details
17
+
- Uses `/tmp/ccusage_statusline.lock` as a mutex to ensure single execution
18
+
- Gracefully skips execution when locked instead of queuing (prevents pile-up)
19
+
- Automatic cleanup of stale locks from crashed processes
20
+
- Fallback timeout mechanism for systems without GNU coreutils
The cc-statusline was causing infinite spawning of ccusage processes, leading to:
5
+
- CPU usage over 300%
6
+
- 30+ simultaneous Node.js processes
7
+
- Memory consumption exceeding 3GB
8
+
- System becoming unresponsive
9
+
10
+
## Root Cause
11
+
The statusline script was calling `npx ccusage@latest blocks --json` without any concurrency control. When Claude Code rapidly triggered the statusline (e.g., every keystroke), multiple ccusage processes would spawn before previous ones completed.
12
+
13
+
## Solution Implemented
14
+
Added a robust file-based locking mechanism with the following features:
15
+
16
+
1.**Process-based semaphore**: Uses `/tmp/ccusage_statusline.lock` directory as a mutex
17
+
2.**PID tracking**: Stores process ID to detect and clean up stale locks
18
+
3.**Timeout protection**: Implements 3-second timeout for ccusage execution
19
+
4.**Cross-platform support**: Works on Linux, macOS, and systems with/without GNU coreutils
20
+
5.**Graceful degradation**: If a lock exists, the script skips ccusage call rather than queuing
21
+
22
+
## Key Changes
23
+
- Modified `src/features/usage.ts` to generate bash code with locking mechanism
24
+
- Added process existence checking with `kill -0`
25
+
- Implemented timeout using `timeout`/`gtimeout` commands where available
26
+
- Added fallback timeout mechanism using background processes for systems without timeout command
0 commit comments