kolibri icon indicating copy to clipboard operation
kolibri copied to clipboard

server.pid reads empty while the starting server rewrites it, failing the DEB install smoke test

Open rtibblesbot opened this issue 1 month ago • 1 comments

❌ This issue is not open for contribution. Visit Contributing guidelines to learn about the contributing process and how to find suitable issues.

Target branch: develop

Observed behavior

  • PIDPlugin.set_pid_file (kolibri/utils/server/__init__.py:385) opens server.pid with "w", so the file is empty between truncate and write.
  • A starting server rewrites the file on ENTER, START, SERVING, ZIP_SERVING and RUN. The HTTP port answers before the last rewrites.
  • check_server_interpreter in platforms/debian/tests/install_smoke_test.sh reads the first line right after port 8080 answers. In that window it gets an empty PID and readlink /proc//exe prints nothing.
  • _read_pid_file returns STATUS_PID_FILE_INVALID on the same empty read, so kolibri status and kolibri stop can hit it too.
  • The DEB install tests / Install test (ubuntu:24.04, no system python3) job failed this way on PR #15692, which changes only QTI frontend files: https://github.com/learningequality/kolibri/actions/runs/40482850475/job/122121833972

Errors and logs

PASS: Kolibri is responding on port 8080 (attempt 1)
FAIL: Kolibri server runs on '', expected /opt/kolibri/python/bin/python3.*

Steps to reproduce

  1. Install the DEB from any PR build in ubuntu:24.04 without system python3.
  2. Run platforms/debian/tests/install_smoke_test.sh.
  3. It fails intermittently at check_server_interpreter.

Acceptance Criteria

  • [ ] A reader of server.pid never sees an empty or partial file while the server writes it.
  • [ ] A test fails when server.pid can be read between truncate and write.

AI usage

Claude Code traced the CI failure to the PID-file write and drafted this issue while handling CI on #15692.

rtibblesbot avatar Oct 27 '26 11:10 rtibblesbot

Plan: Readers of server.pid never see an empty or partial file while the server rewrites it (#15693).

  • [ ] Write server.pid atomically
  • [ ] Self-review the produced code

Assumptions — the issue did not settle these; say so if one is wrong.

  • When Windows refuses os.replace (open reader), fall back to the in-place write; if strict atomicity is wanted there, this becomes a retry and the fallback test changes.
  • Fixed temp name, not mkstemp; if two servers can start on one KOLIBRI_HOME at once, their temp writes collide and this needs mkstemp.

Written by rtibblesbot, an LLM-based coding agent.

rtibblesbot avatar Oct 30 '26 12:10 rtibblesbot