Skip to content

fix(project-backend): replace persistent control ports with dynamic endpoints - #1011

Merged
wuzhiming merged 4 commits into
cocos:mainfrom
DecviL:main-fix-1026
Oct 26, 2026
Merged

wuzhiming merged 4 commits into
cocos:mainfrom
DecviL:main-fix-1026

Conversation

@DecviL

@DecviL DecviL commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

Background

PinK 0.0.2.0 fails to start a project on an exFAT drive because backend ownership acquisition publishes a persistent port registry using a hard link, which exFAT does not support. The reported failure is EISDIR in ProjectBackendLease.acquire.

Bug report: https://forum.cocos.org/t/topic/177872/5?u=weijinda

Persisting a control port across restarts can also block normal startup when that port has subsequently been allocated to another project or application.

Implementation

  • Remove the persistent rendezvous/port.json registry and hard-link publication. Each backend startup binds 127.0.0.1 on port 0, allowing the OS to allocate a currently available control port.
  • Atomically publish the instance address and credentials in owner.json. Discovery validates the live project and instance identity; missing, corrupt, unrelated, or unresponsive stale metadata does not pin a new startup to an old port.
  • Obtain a newly spawned backend's readiness descriptor directly over parent/child IPC, so overlapping owner.json writes cannot make a caller mistake another process for its own child.
  • Query and stop a specific instance using its descriptor and authenticated control endpoint. Retain stale discovery metadata on shutdown to avoid deleting another instance's newer publication.
  • Update lifecycle tests and documentation. No dependencies are added.

Behavior change: cross-process project exclusivity is no longer enforced. Independent startup commands may create separate backends for the same project; callers must coordinate concurrent project writes. ensureProjectBackend reuses a discoverable backend and shares concurrent startup requests within the calling process. Old registry paths are neither read nor migrated.

Testing

  • Passed: TypeScript build:
    node node_modules/typescript/bin/tsc -b
  • Passed on Windows / NTFS: 16 tests covering dynamic ports, concurrent subprocess startup, stale or corrupt metadata, former ports occupied by unrelated or unresponsive services, authenticated shutdown, and launcher cleanup:
    node node_modules/jest/bin/jest.js --config jest.config.ts --runInBand --runTestsByPath tests/project-backend-client.test.ts tests/project-backend-ownership.test.ts tests/project-backend-launcher.test.ts --silent
  • Passed on an actual exFAT volume (E:): all 10 backend discovery/ownership tests with COCOS_BACKEND_TEST_TMPDIR=E:\. The Windows junction assertion is omitted when a custom test directory is configured.
  • Passed: real managed MCP/Scene backend integration test with COCOS_TEST_PROJECT_BACKEND=1, covering startup, reuse, explicit shutdown, restart, and stale-descriptor handling.
  • Passed: git diff --check.

@DecviL
DecviL requested a review from bofeng-song October 26, 2026 02:52

@wuzhiming wuzhiming left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

未发现本次改动引入且有充分证据可确认的问题,仅完成静态审查,不代表测试通过。审查范围:三个文件的所提供 patch;对照 base 与 head 的 ownership.ts,并读取 head 的启动客户端、Launcher、所有权测试及相关测试辅助代码,核对并发发布、注册信息校验、监听器关闭和临时目录清理。无 patch 的相关文件仅用于验证调用关系,未作完整审查。未运行测试或构建,未实测 Windows、NTFS/exFAT 的目录重命名行为及真实后端集成;文档仅审查所提供差异。固定审查提交:18e3dce7,对照基线:e683ccc8。

PR 审查:#1011
审查提交:18e3dce7090adaf66c554fd1e6db8aa462f86b4e
Base:e683ccc80479aeda84365121f7bb5597f456c38f

验证范围:3 个变更文件,另读取 8 个提交内文件;静态审查,未运行构建或测试,未修改代码。

@DecviL DecviL changed the title fix(project-backend): support exFAT with atomic directory publication fix(project-backend): replace persistent control ports with dynamic endpoints Oct 26, 2026
@wuzhiming
wuzhiming merged commit 4f4ee05 into cocos:main Oct 26, 2026
7 of 8 checks passed
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.

2 participants