Skip to content

refactor: Improve TCP IPC robustness (port config, error handling, cleanup) #14

@wilcorrea

Description

@wilcorrea

Summary

CodeRabbit identified several robustness issues in the TCP IPC implementation:

1. Hardcoded Port Conflicts with Neo4j (Major - tcp_ipc.rs:8)

Port 7474 is Neo4j's default HTTP port. The TCP bind happens asynchronously inside a spawned task, but if another process holds the port, the error is only logged to stderr.

Recommendations:

  • Make the port configurable (via config file or environment variable)
  • Consider a fallback port range
  • Synchronously bind before spawning the listener loop to catch conflicts early

2. setup() Always Returns Ok(()) (Major - tcp_ipc.rs:35, lib.rs:419)

Because TcpListener::bind happens inside the spawned async task, setup() returns Ok(()) before the bind attempt completes. The caller in lib.rs:417 checks for Err but will never see one from a bind failure, making the error handling dead code.

Recommendations:

  • Synchronously bind before spawning the accept loop, OR
  • Use a oneshot channel to relay the bind result back to the caller
  • Propagate actual bind errors to the caller

3. cleanup() Doesn't Actually Stop the TCP Listener (Major - tcp_ipc.rs:43)

cleanup() only clears the stored address string from state. The TcpListener and its accept loop (and any active client connections) continue running because the listener is owned by the spawned task, not by TcpSocketState.

Unlike the Unix socket ipc::cleanup() which removes the socket file, this cleanup is purely cosmetic.

Recommendations:

  • Store a cancellation mechanism (tokio::sync::watch, CancellationToken, or JoinHandle) in TcpSocketState
  • Modify the accept loop to check for cancellation
  • In cleanup(), signal cancellation or abort the JoinHandle

References

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