fix: start gateway before control channel
This commit is contained in:
@@ -6,6 +6,7 @@
|
|||||||
- Package contents: include Discord/hooks build outputs in the npm tarball to avoid missing module errors.
|
- Package contents: include Discord/hooks build outputs in the npm tarball to avoid missing module errors.
|
||||||
- Heartbeat replies now drop any output containing `HEARTBEAT_OK`, preventing stray emoji/text from being delivered.
|
- Heartbeat replies now drop any output containing `HEARTBEAT_OK`, preventing stray emoji/text from being delivered.
|
||||||
- macOS menu now refreshes the control channel after the gateway starts and shows “Connecting to gateway…” while the gateway is coming up.
|
- macOS menu now refreshes the control channel after the gateway starts and shows “Connecting to gateway…” while the gateway is coming up.
|
||||||
|
- macOS local mode now waits for the gateway to be ready before configuring the control channel.
|
||||||
|
|
||||||
## 2.0.0-beta3 — 2025-12-27
|
## 2.0.0-beta3 — 2025-12-27
|
||||||
|
|
||||||
|
|||||||
@@ -22,13 +22,6 @@ final class ConnectionModeCoordinator {
|
|||||||
case .local:
|
case .local:
|
||||||
await RemoteTunnelManager.shared.stopAll()
|
await RemoteTunnelManager.shared.stopAll()
|
||||||
WebChatManager.shared.resetTunnels()
|
WebChatManager.shared.resetTunnels()
|
||||||
do {
|
|
||||||
try await ControlChannel.shared.configure(mode: .local)
|
|
||||||
} catch {
|
|
||||||
// Control channel will mark itself degraded; nothing else to do here.
|
|
||||||
self.logger.error(
|
|
||||||
"control channel local configure failed: \(error.localizedDescription, privacy: .public)")
|
|
||||||
}
|
|
||||||
let shouldStart = GatewayAutostartPolicy.shouldStartGateway(mode: .local, paused: paused)
|
let shouldStart = GatewayAutostartPolicy.shouldStartGateway(mode: .local, paused: paused)
|
||||||
if shouldStart {
|
if shouldStart {
|
||||||
GatewayProcessManager.shared.setActive(true)
|
GatewayProcessManager.shared.setActive(true)
|
||||||
@@ -39,9 +32,17 @@ final class ConnectionModeCoordinator {
|
|||||||
{
|
{
|
||||||
Task { await GatewayProcessManager.shared.ensureLaunchAgentEnabledIfNeeded() }
|
Task { await GatewayProcessManager.shared.ensureLaunchAgentEnabledIfNeeded() }
|
||||||
}
|
}
|
||||||
|
_ = await GatewayProcessManager.shared.waitForGatewayReady()
|
||||||
} else {
|
} else {
|
||||||
GatewayProcessManager.shared.stop()
|
GatewayProcessManager.shared.stop()
|
||||||
}
|
}
|
||||||
|
do {
|
||||||
|
try await ControlChannel.shared.configure(mode: .local)
|
||||||
|
} catch {
|
||||||
|
// Control channel will mark itself degraded; nothing else to do here.
|
||||||
|
self.logger.error(
|
||||||
|
"control channel local configure failed: \(error.localizedDescription, privacy: .public)")
|
||||||
|
}
|
||||||
Task.detached { await PortGuardian.shared.sweep(mode: .local) }
|
Task.detached { await PortGuardian.shared.sweep(mode: .local) }
|
||||||
|
|
||||||
case .remote:
|
case .remote:
|
||||||
|
|||||||
@@ -320,6 +320,21 @@ final class GatewayProcessManager {
|
|||||||
Task { await ControlChannel.shared.configure() }
|
Task { await ControlChannel.shared.configure() }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func waitForGatewayReady(timeout: TimeInterval = 6) async -> Bool {
|
||||||
|
let deadline = Date().addingTimeInterval(timeout)
|
||||||
|
while Date() < deadline {
|
||||||
|
if !self.desiredActive { return false }
|
||||||
|
do {
|
||||||
|
_ = try await GatewayConnection.shared.requestRaw(method: .health, timeoutMs: 1500)
|
||||||
|
return true
|
||||||
|
} catch {
|
||||||
|
try? await Task.sleep(nanoseconds: 300_000_000)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
self.appendLog("[gateway] readiness wait timed out\n")
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
func clearLog() {
|
func clearLog() {
|
||||||
self.log = ""
|
self.log = ""
|
||||||
try? FileManager.default.removeItem(atPath: LogLocator.launchdGatewayLogPath)
|
try? FileManager.default.removeItem(atPath: LogLocator.launchdGatewayLogPath)
|
||||||
|
|||||||
Reference in New Issue
Block a user