OS.create_process returned a PID for a missing binary
In lazydeck, the Godot editor plugin starts lazydeck serve from api/server_launcher.gd with OS.create_process(), and treated pid <= 0 as the failure. I checked that on Godot 4.7.2 for Linux. A missing executable still comes back with a positive PID: Godot forks, and the child fails to exec and exits. The check never fired. With no lazydeck on PATH, the dock logged Starting lazydeck serve (…, pid N)… and, five seconds later, Could not find a running lazydeck serve. The fix is lazydeck#133 (fd8d7b1).
A positive PID was a successful fork
start_if_needed() passed the configured name straight through. The comment called -1 the only documented failure:
# create_process() returns the new PID, or -1 if it couldn't be created —
# not a Godot Error code, so error_string() isn't meaningful here. -1 is
# the only documented failure value; anything else non-positive is
# reported as-is rather than guessed at.
var pid := OS.create_process(binary, PackedStringArray(["serve"]))
if pid <= 0:
-1 is a failed fork. On the Linux editor I checked, a missing file is a successful fork, so the PID is positive and the child is already gone. The dock had already logged the start, then waited out a fixed loop:
for attempt in 20:
await get_tree().create_timer(0.25).timeout
located = LazyDeckConnectionLocator.load_connection()
if located.get("ok", false):
break
That is 20 times 0.25 s. load_connection() then returns no connection file at … (is lazydeck serve running?), and the dock logs it as Could not find a running lazydeck serve.
Resolve the executable first
resolve_executable() runs before the spawn. An absolute path has to exist. A bare name is the first match on PATH, and on Windows a name with no extension is also tried as .exe. A relative path is returned unchecked, because it resolves against the editor's working directory, which this cannot see reliably. Nothing found returns "".
static func resolve_executable(binary: String) -> String:
if binary.contains("/") or binary.contains("\\"):
if binary.is_absolute_path() and not FileAccess.file_exists(binary):
return ""
return binary
var windows := OS.get_name() == "Windows"
var names := PackedStringArray([binary])
if windows and binary.get_extension() == "":
names.append(binary + ".exe")
for directory in OS.get_environment("PATH").split(";" if windows else ":", false):
for name in names:
var candidate := directory.path_join(name)
if FileAccess.file_exists(candidate):
return candidate
return ""
A miss names LAZYDECK_BIN and the project setting lazydeck/server/executable. The pid <= 0 check stays, on the resolved path, for a fork that fails. The new comment also names macOS for the same fork-before-exec. The editor I checked was Linux.
# Checked before spawning: on Linux and macOS create_process() forks
# first, so a missing executable still returns a positive PID (the child
# fails to exec and exits). Only a failed fork returns -1.
var resolved := resolve_executable(binary)
if resolved == "":
return {
"started": false,
"error":
(
"lazydeck serve auto-start failed: %s was not found (set LAZYDECK_BIN or %s)"
% [binary, EXECUTABLE_SETTING]
),
}
var pid := OS.create_process(resolved, PackedStringArray(["serve"]))
Stop when the child has exited
wait_for_connection() replaces the dock's loop. The cap is still 5 seconds, and each pass still waits 0.25 s. The pass that finds the process gone, with no connection file, returns then:
while not located.get("ok", false) and Time.get_ticks_msec() < deadline:
await tree.create_timer(0.25).timeout
located = LazyDeckConnectionLocator.load_connection()
if not located.get("ok", false) and not OS.is_process_running(pid):
return {
"ok": false,
"error":
(
"lazydeck serve (pid %d) exited before it was ready; run `%s serve` in a terminal to see why"
% [pid, executable()]
),
}
A serve that crashes while starting, a bad devices.toml for example, takes that path. The dock waits with the PID from start_if_needed():
located = await LazyDeckServerLauncher.wait_for_connection(
get_tree(), int(launch.get("pid", 0))
)
What the test printed
integrations/godot/tests/autostart_test.gd runs from scripts/godot-integration-test.sh after the main test, once the fixture server is stopped and its connection file is gone. It sets LAZYDECK_BIN and LAZYDECK_AUTOSTART itself, so the result does not depend on the caller's environment.
Auto-start 0 refuses with a reason. /nonexistent/lazydeck and no-such-lazydeck-binary are refused before a spawn; the error contains not found. false is on PATH, so it starts, false serve exits 1 at once, and the test fails if reporting that takes more than 2000 ms. The pull request's godot-integration job printed autostart: an early exit is reported after 222 ms under Godot 4.7.1, then autostart: all cases passed. Locally the same cases passed on Godot 4.7.2.
The real start is LAZYDECK_TEST_FIXTURE_BIN, a wrapper that execs lazydeck serve --fixture. The connection file appears, a health request answers, and a second start_if_needed() sees that file and does not spawn.
What I would repeat
- A PID is not proof the program started. On Godot 4.7.2 for Linux,
OS.create_process()forks first. A missing executable still returns a positive PID. Only a failed fork returns-1. - Resolve the executable before spawning. An absolute path has to exist. A bare name is a
PATHlookup, with.exeon Windows when the name has no extension. A relative path passes through. - Watch for an early exit. A fixed 20 × 0.25 s wait turns a crash on startup, including a bad
devices.toml, into the same missing connection file five seconds later.