Skip to content

Improve socket protocol robustness #104

@ng

Description

@ng

Summary

Enhance socket communication reliability with minor protocol improvements from CodeRabbit review.

Tasks

1. Strip carriage returns in argument sanitization

Location: src/hardware/socketClient.ts:47
Priority: Low

Currently only strips \n but leaves \r. If hardware daemon interprets \r as line ending, injected \r could confuse protocol.

Fix: Replace /\n/g with /[\r\n]/g in cleanArg sanitization.

2. Propagate socket errors to prevent hanging reads

Location: src/hardware/socketClient.ts:23-25
Priority: Low

Socket error handler only logs but doesn't propagate error state. In-flight readMessage() calls won't know socket is unhealthy until 30s timeout.

Fix:

  • Set internal error flag when socket error occurs
  • Forward error to MessageStream via this.messageStream.destroy(error)

3. Make command delay configurable

Location: src/hardware/socketClient.ts:55-56
Priority: Low

Hardcoded 10ms delay adds latency to every command. Should be configurable or removed if not needed.

Fix:

  • Add commandDelayMs option to SocketClient constructor (default 0)
  • Replace literal 10 with the option value
  • Update connectToSocket() to pass option

Source: CodeRabbit PR #100 review

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions