Skip to content

fix(core): eliminate status/connections file race conditions on macOS (closes #535)#541

Merged
s2x merged 1 commit into
masterfrom
fix/issue-535-macos-workerman-command-tests
Jul 1, 2026
Merged

fix(core): eliminate status/connections file race conditions on macOS (closes #535)#541
s2x merged 1 commit into
masterfrom
fix/issue-535-macos-workerman-command-tests

Conversation

@s2x

@s2x s2x commented Jul 1, 2026

Copy link
Copy Markdown
Collaborator

Description

Closes #535

WorkermanCommandTest fails on macOS because of a race condition in status/connections file reading. Workerman's SIGIOT handler truncates the status file to 0 bytes before writing content. PHP's stat cache combined with stale status files from interrupted runs causes waitForFile() to detect the file before content is written, returning empty or partial data.

Changes

  • StatusFileReader::waitForFile(): Call clearstatcache() before each poll to avoid cached stale stats. Reject 0-byte files (written during the SIGIOT handler's truncate phase).

  • ServerManager::getStatus() / getConnections(): Delete the stale status/connections file @unlink() before sending SIGIOT/SIGIO, so waitForFile() always waits for fresh output from the current signal.

  • StatusFileReaderTest: Write content to the temp file in testWaitForFileReturnsTrueWhenFileExists (previously empty). Add testWaitForFileReturnsFalseWhenFileEmpty to cover the 0-byte rejection path.

Changelog

Fix race condition in ServerManager::getStatus() / getConnections() where PHP's stat cache and stale status files could cause waitForFile() to read an empty or incomplete file. StatusFileReader::waitForFile() now clears the stat cache per poll and rejects 0-byte files. ServerManager deletes the stale file before signaling, ensuring fresh output is waited for.

Code Review

  • Passed subagent code review
  • All review comments addressed

@s2x s2x self-assigned this Jul 1, 2026
@s2x
s2x merged commit 51135ab into master Jul 1, 2026
12 checks passed
@s2x
s2x deleted the fix/issue-535-macos-workerman-command-tests branch July 1, 2026 16:14
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.

[Bug] WorkermanCommandTest (4 tests) fail on macOS — CLI commands fail or connection does not drop after stop

1 participant