fix(client): address PR #5 review — race condition, buffer corruption, input error
Critical fixes from Hoshe review: 1. Race condition: defer TCP connect to _process() with retry logic (MAX_CONNECT_RETRIES=20, 100ms interval) so server has time to bind. 2. Buffer corruption: disconnect on oversized message instead of clearing valid buffered data (_corrupt flag, fail-safe). 3. Silent input drop: send_input() returns Error so callers can detect encode/validation failures. Warnings addressed: - ServerProcess validates server_path exists before spawning - SIGKILL and health check TODOs documented for future work - Diagonal keybindings documented as intentional deferral - send_message uses single put_data() call (no partial write risk) - Static frame helpers documented as D-030 Layer 2 test-only New tests (36 total, up from 33): - Partial read scenario (chunked TCP delivery) - Multi-message sequential decode (exercises buffer corruption fix) - send_input error return on invalid action Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -5,10 +5,14 @@ var _pid: int = -1
|
||||
|
||||
|
||||
## Start the server process. Returns the PID, or -1 on failure.
|
||||
## Validates that server_path exists and is accessible before spawning.
|
||||
func start(server_path: String, args: Array = []) -> int:
|
||||
if _pid > 0 and is_alive():
|
||||
push_warning("ServerProcess: server already running (pid %d)" % _pid)
|
||||
return _pid
|
||||
if not FileAccess.file_exists(server_path):
|
||||
push_error("ServerProcess: server binary not found at %s" % server_path)
|
||||
return -1
|
||||
_pid = OS.create_process(server_path, args)
|
||||
if _pid <= 0:
|
||||
push_error("ServerProcess: failed to start server at %s" % server_path)
|
||||
@@ -16,6 +20,8 @@ func start(server_path: String, args: Array = []) -> int:
|
||||
|
||||
|
||||
## Check if the server process is still running.
|
||||
## NOTE: OS.is_process_running() doesn't distinguish starting/healthy/zombie.
|
||||
## TODO: Add health check (e.g. TCP readiness probe) when server supports it.
|
||||
func is_alive() -> bool:
|
||||
if _pid <= 0:
|
||||
return false
|
||||
@@ -23,6 +29,7 @@ func is_alive() -> bool:
|
||||
|
||||
|
||||
## Stop the server process.
|
||||
## TODO: Send graceful shutdown signal before SIGKILL when server supports it.
|
||||
func stop() -> void:
|
||||
if _pid > 0 and is_alive():
|
||||
OS.kill(_pid)
|
||||
|
||||
Reference in New Issue
Block a user