2 Commits
1.0.3 ... 1.0.6

Author SHA1 Message Date
wenzuhuai
30fb5d8b27 fix: 将断网场景的错误日志降级为 debug 级别
- Error closing connection 降级为 debug(TLS 关闭错误是断网预期行为)
- Write failed: batchBuffer is nil 降级为 debug
- Write operation failed 降级为 debug
- 避免长时间断网恢复时日志泛滥
2026-01-23 09:34:33 +08:00
wenzuhuai
cd680abe55 fix: 修复 errorCaught 导致的频繁重连问题
- 移除 errorCaught 中重复的 handleDisconnect 调用
- 将 uncleanShutdown 日志降级为 debug 级别
- 避免双重触发导致的断开重连循环
2026-01-23 09:06:50 +08:00

View File

@@ -921,14 +921,14 @@ class ConnectionHandler: ChannelInboundHandler {
if let natsErr = error as? NatsErrorProtocol {
self.fire(.error(natsErr))
} 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
let currentState = state.withLockedValue { $0 }
if currentState != .closed && currentState != .disconnected {
handleDisconnect()
}
// handleDisconnect
// context.close() channelInactive
//
}
func handleDisconnect() {
@@ -987,7 +987,8 @@ class ConnectionHandler: ChannelInboundHandler {
try result.get()
self.fire(.disconnected)
} catch {
logger.error("Error closing connection: \(error)")
// debug TLS
logger.debug("Connection closed with error (will reconnect): \(error)")
}
// Only start reconnect after disconnect is complete
self.handleReconnect()
@@ -1060,7 +1061,8 @@ class ConnectionHandler: ChannelInboundHandler {
// Trigger reconnect to recover
let currentState = state.withLockedValue { $0 }
if currentState == .connected {
logger.error("Write failed: batchBuffer is nil but state is connected, triggering reconnect")
// debug
logger.debug("Write failed: batchBuffer is nil, triggering reconnect")
handleDisconnect()
}
throw NatsError.ClientError.invalidConnection("not connected")
@@ -1071,7 +1073,8 @@ class ConnectionHandler: ChannelInboundHandler {
// Trigger reconnect on write failure - connection may be broken
let currentState = state.withLockedValue { $0 }
if currentState == .connected {
logger.error("Write operation failed, triggering reconnect: \(error)")
// debug
logger.debug("Write operation failed, triggering reconnect: \(error)")
handleDisconnect()
}
throw NatsError.ClientError.io(error)