Sitelet https://github.com/Netis/cloud-probe/issues/264
Skip to content

cpdaemon refuses to start when cpm-worker.pid names an unrelated process, or ends with a newline #264

Description

@vaderyang

Summary

killOrphanWorker (cpdaemon/pkg/cpm/syncer.go) treats the worker pid file as authoritative. If the recorded pid now belongs to any other process, it returns unexpected command line: .... NewSyncer fails and cpdaemon exits. A pid file of the form "<pid>\n" (the usual format) fails strconv.Atoi in the same way.

Why it matters

  • The default pid file cpm-worker.pid is relative to the working directory and survives reboots.
  • After a reboot or a crash, the old pid is commonly reused by an unrelated process.
  • cpdaemon then fails on every restart, and the probe stays down until someone deletes the file by hand.

Expected

A pid file is only a hint; start-stop-daemon(8) --pidfile checks the process before acting. Therefore:

  • if the pid names a live worker (the same executable), kill it and start;
  • if it names a dead or an unrelated process, ignore it and start;
  • surrounding whitespace in the pid file should be trimmed.

Reproduction

cpdaemon/pkg/cpm/syncer_startup_test.go (both registered as known failures in verification/policy.toml):

  • TestNewSyncer_PidFileNamesUnrelatedProcess fails with kill orphan worker error: unexpected command line: /bin/sleep 30.
  • TestNewSyncer_PidFileWithTrailingNewline fails with strconv.Atoi: parsing "511958\n": invalid syntax.

Found by the verification-coverage work, round 7 (branch feat/verification-coverage, requirement REQ-DAEMON-STARTUP, risk RISK-DAEMON-WONT-START).

中文原文

killOrphanWorker 把 pid 文件当成事实:pid 若被其他进程复用,就返回 "unexpected command line",导致 NewSyncer 失败、cpdaemon 退出。默认 cpm-worker.pid 位于工作目录、跨重启保留,重启后 pid 复用很常见,于是 cpdaemon 每次重启都失败,直到有人手工删除该文件。以 "\n" 结尾的 pid 文件同样会导致启动失败。

期望:pid 文件只是提示。指向本 worker 就杀掉;指向死进程或无关进程就忽略并正常启动;读取时去掉首尾空白。

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions