Skip to content

fix(p3): async file lock for event loop blocking (Issue #763)#794

Open
jlin53882 wants to merge 1 commit into
CortexReach:masterfrom
jlin53882:fix/p3-async-file-lock-clean
Open

fix(p3): async file lock for event loop blocking (Issue #763)#794
jlin53882 wants to merge 1 commit into
CortexReach:masterfrom
jlin53882:fix/p3-async-file-lock-clean

Conversation

@jlin53882
Copy link
Copy Markdown
Contributor

Summary

Issue #763 P3: Event Loop Blocking in runWithFileLock()

Convert 5 synchronous I/O calls to async versions to prevent event loop blocking:

Before (Sync) After (Async)
existsSync pathExists() [access]
mkdirSync await mkdir()
writeFileSync await writeFile()
statSync await stat()
unlinkSync await unlink()

Changes

  • Add node:fs/promises imports (access, mkdir, stat, unlink, writeFile)
  • Add pathExists() static helper (async equivalent of existsSync)
  • Convert init block to async (mkdir + writeFile)
  • Convert stale check to async (stat + unlink)
  • Add unit tests (5 tests pass)

Tests

node --test test/p3-async-file-lock.test.mjs
# 5/5 tests passed

Fixes

Checklist

  • Security: No vulnerabilities
  • Performance: Async I/O prevents blocking
  • Correctness: Error handling preserved
  • Testing: 5 unit tests pass
  • CI manifest updated

P3 修復:runWithFileLock() 的 5 個 sync I/O → async:
- existsSync → pathExists() [static async, use access() + constants.F_OK]
- mkdirSync  → await mkdir()
- writeFileSync → await writeFile()
- statSync   → await stat()
- unlinkSync → await unlink()

新增 pathExists() static helper,回傳 Promise<boolean>。
async I/O 不會 block event loop,解決高併發情境下的效能瓶頸。

測試:5/5 通過(pathExists + init + stale check)
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