Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions macos/CursorAPI/Sources/CursorAPICore/LocalAPIServer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,11 @@ public final class LocalAPIServer: @unchecked Sendable {
let endpointPort = NWEndpoint.Port(rawValue: port)!
let parameters = NWParameters.tcp
parameters.requiredLocalEndpoint = NWEndpoint.hostPort(host: "127.0.0.1", port: endpointPort)
// Sockets from the previous run can linger after a restart. Without
// endpoint reuse the rebind fails, the fallback picks the next port, and
// that new port gets persisted, so every restart moves the API and
// breaks anything configured against it.
parameters.allowLocalEndpointReuse = true
let listener = try NWListener(using: parameters)
let startResult = ListenerStartResult(port: port)
listener.newConnectionHandler = { [weak self] connection in
Expand Down