fix: 修复 errorCaught 导致的频繁重连问题
- 移除 errorCaught 中重复的 handleDisconnect 调用 - 将 uncleanShutdown 日志降级为 debug 级别 - 避免双重触发导致的断开重连循环
This commit is contained in:
@@ -921,14 +921,14 @@ class ConnectionHandler: ChannelInboundHandler {
|
|||||||
if let natsErr = error as? NatsErrorProtocol {
|
if let natsErr = error as? NatsErrorProtocol {
|
||||||
self.fire(.error(natsErr))
|
self.fire(.error(natsErr))
|
||||||
} else {
|
} else {
|
||||||
logger.error("unexpected error: \(error)")
|
// 降级为 debug 级别,避免频繁输出错误日志
|
||||||
|
// uncleanShutdown 是常见的 TLS 关闭情况,不需要作为错误处理
|
||||||
|
logger.debug("Channel error (will reconnect if needed): \(error)")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Unified handling: use handleDisconnect for all non-closed/non-disconnected states
|
// 注意:不在这里调用 handleDisconnect
|
||||||
let currentState = state.withLockedValue { $0 }
|
// context.close() 会触发 channelInactive,由它负责处理断开逻辑
|
||||||
if currentState != .closed && currentState != .disconnected {
|
// 这样可以避免重复处理和过度重连
|
||||||
handleDisconnect()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func handleDisconnect() {
|
func handleDisconnect() {
|
||||||
|
|||||||
Reference in New Issue
Block a user