【Azure Relay】记录使用Azure Relay在通信中遇见侦听器(Listener)或发送端(Sender)断开时的异常日志 (Hybrid Connection by Websocket)

发布时间:2026/7/9 9:28:40

【Azure Relay】记录使用Azure Relay在通信中遇见侦听器(Listener)或发送端(Sender)断开时的异常日志 (Hybrid Connection by Websocket) 它是一种单对单的通信方式需要对服务端和客户端代码有一些改动才可以需要定义服务端侦听器(Listener)来接受消息客户端(Caller)来发送消息。服务端侦听器(Listener) 使用 HybridConnectionListener 对象来初始化对象客户端发送者(Caller)使用 HybridConnectionClient 对象来初始化对象Azure Relay的工作原理如下原理图流程说明Listening client sends a listening request to the Azure Relay service. The Azure load balancer routes the request to one of the gateway nodes.The Azure Relay service creates a relay in the gateway store.Sending client sends a request to connect to the listening service.The gateway that receives the request looks up for the relay in the gateway store.The gateway forwards the connection request to the right gateway mentioned in the gateway store.The gateway sends a request to the listening client for it to create a temporary channel to the gateway node thats closest to the sending client.The listening client creates a temporary channel to the gateway thats closest to the sending client. Now that the connection is established between clients via a gateway, the clients can exchange messages with each other.The gateway forwards any messages from the listening client to the sending client.The gateway forwards any messages from the sending client to the listening client.基于以上的理解当Listener 或 Caller 都突然中断的时候 Listener端会记录什么异常日志呢Caller端会记录什么异常日志呢问题解答第一部分Caller端异常退出的情况 Listener会记录什么日志呢结果在Listener的日志中会输出如下的错误消息。如果不对异常进行处理会导致整个进程奔溃Listener退出。Exception in processing connection: Microsoft.Azure.Relay.RelayException: The remote party closed the WebSocket connection without completing the close handshake. TrackingId:xxx-xx-xx-xx-xxxx4_G8_G9, Address:sb://xxxxxxxx.servicebus.chinacloudapi.cn/xxxxxxxt01, Timestamp:5/17/2026 8:48:56 AM --- System.Net.WebSockets.WebSocketException: The remote party closed the WebSocket connection without completing the close handshake. at System.Net.WebSockets.WebSocketBase.WebSocketOperation.Processd__19.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Net.WebSockets.WebSocketBase.ReceiveAsyncCored__45.MoveNext() --- End of stack trace from previous location where exception was thrown ---实验分别启动Listener 和 Caller在正常通信两次后直接关闭Caller窗口第二部分Listener端异常退出的情况 Caller会记录什么日志呢结果在Caller的日志中会输出如下的错误消息。Microsoft.Azure.Relay.RelayException: The remote party closed the WebSocket connection without completing the close handshake. TrackingId:xxxx-x-x-xx-xxxx5e79e2e, Address:sb://xxxxxx.servicebus.chinacloudapi.cn/xxxxxxst01, Timestamp:5/17/2026 9:29:11 AM --- System.Net.WebSockets.WebSocketException: The remote party closed the WebSocket connection without completing the close handshake. at System.Net.WebSockets.WebSocketBase.WebSocketOperation.Processd__19.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Net.WebSockets.WebSocketBase.ReceiveAsyncCored__45.MoveNext()实验分别启动Listener 和 Caller在正常通信后直接关闭Listener窗口对比两种情况下的日志都是Microsoft.Azure.Relay.RelayException: The remote party closed the WebSocket connection without completing the close handshake.微小的区别在异常消息中的TrackingId格式不同如果是Caller异常断开TrackingId中会携带 _GX_GX 标识比如 TrackingId:xxx-xx-xx-xx-xxxx4_G8_G9

相关新闻