Skip to content

findAvailablePort returns port without confirming availability #48

Description

@ComfyChloe

Problem

findAvailablePort synchronously creates a net.Server, calls server.listen(port, ...) with a callback, and immediately returns the port without waiting for the callback to fire. On a system where the port is already in use, listen fires an error asynchronously that the function never observes, but the function already returned that port. OSC service initialize() then hands the unverified port to osc.UDPPort({ localPort: this.localPort, ... }) which either quietly fails to bind, or worse, replaces whatever was listening on that port (if the kernel lets UDP and TCP collide).

Evidence

main/services/oscService.ts:401-410
    findAvailablePort(startPort: number, endPort: number): number {
        const net = require('net')
        for (let port = startPort; port <= endPort; port++) {
            try {
                const server = net.createServer()
                server.listen(port, () => {
                    server.close()
                })
                return port
            } catch (_error) { continue }
        }
        return startPort
    }

File: main/services/oscService.ts:401 in ComfyChloe/ARC-Client.

Suggested fix

Make this an async helper that wraps listen in a Promise, attaches both listening (close immediately and resolve the port) and error (reject) handlers, and falls through to the next port on EADDRINUSE. The current pattern only catches synchronous throws, not the async EADDRINUSE case.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Area: Client RuntimeElectron app runtime / main processbugSomething isn't working

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions