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

简介: Azure Relay 是一种中继服务,用于在无法直连的客户端与服务端间建立安全通信通道。其核心为 HybridConnectionListener(服务端)与 HybridConnectionClient(客户端),基于 WebSocket 实现双向消息传递。异常断开时,双方均记录 `RelayException`,提示“远程方未完成关闭握手”,仅 TrackingId 格式可区分断开方。

问题描述

使用Azure Relay服务,可以帮助服务器与客户端无法直接访问的情况下,提供牵线搭桥中转的沟通方式,俗称“中继”。

它是一种单对单的通信方式,需要对服务端和客户端代码有一些改动才可以,需要定义服务端侦听器(Listener)来接受消息,客户端(Caller)来发送消息。

  • 服务端侦听器(Listener): 使用 HybridConnectionListener 对象来初始化对象
  • 客户端发送者(Caller):使用 HybridConnectionClient 对象来初始化对象

 

Azure Relay的工作原理如下

原理图:

流程说明:

  1. Listening client sends a listening request to the Azure Relay service. The Azure load balancer routes the request to one of the gateway nodes.
  2. The Azure Relay service creates a relay in the gateway store.
  3. Sending client sends a request to connect to the listening service.
  4. The gateway that receives the request looks up for the relay in the gateway store.
  5. The gateway forwards the connection request to the right gateway mentioned in the gateway store.
  6. The gateway sends a request to the listening client for it to create a temporary channel to the gateway node that's closest to the sending client.
  7. The listening client creates a temporary channel to the gateway that's closest to the sending client. Now that the connection is established between clients via a gateway, the clients can exchange messages with each other.
  8. The gateway forwards any messages from the listening client to the sending client.
  9. 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.<Process>d__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.<ReceiveAsyncCore>d__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.<Process>d__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.<ReceiveAsyncCore>d__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
  • 如果是Listener异常断开,TrackingId中不会携带,它的值就是普通的guid字符串,如TrackingId:xxx-xx-xx-xx-xxxxxx0a5

以上内容,供您参考。

 

参考资料

什么是 Azure 中继?https://docs.azure.cn/zh-cn/azure-relay/relay-what-is-it

开始在 .NET 中使用中继混合连接 WebSocket : https://docs.azure.cn/zh-cn/azure-relay/relay-hybrid-connections-dotnet-get-started

 



当在复杂的环境中面临问题,格物之道需:浊而静之徐清,安以动之徐生。 云中,恰是如此!

相关文章
|
2月前
|
人工智能 机器人 Shell
在公司蒸馏我之前,我先赛博飞升
OpenClaw(龙虾)是一款开源AI数字分身框架,可本地或云端部署,支持多模型接入(Claude、Qwen、Ollama等)及钉钉/飞书/Telegram等10+聊天平台。它不止聊天,还能操作浏览器、读写文件、执行命令,并通过插件实现“蒸馏人物”、自动化办公等高级能力,主打隐私可控、真能干活。
485 11
|
2月前
|
存储 弹性计算 安全
阿里云服务器活动实例选择指南:经济型、通用算力型u1/u2i/u2a、九代c9i/g9i/r9i对比与选择
阿里云目前活动中提供了多种云服务器实例规格,包括经济型e、通用算力型u1/u2i/u2a及九代c9i/g9i/r9i实例。经济型e实例适合轻负载应用,通用算力型u1实例以稳定性和高性价比受企业青睐,u2i实例性能较u1提升40%,u2a实例性价比高。九代实例则代表最高技术水平,适合高性能需求场景。用户可根据需求和预算选择,初创企业可选u1实例,业务增长可升级至u2i或u2a,重负载场景则可选九代实例。
|
24天前
|
缓存 监控 安全
别再让Docker占满你的硬盘!一篇搞定docker system所有命令
本指南详解 `docker system` 命令组,助你精准诊断与优雅清理 Docker 占用空间:`df` 查磁盘、`prune` 清资源、`info` 看配置、`events` 监事件。覆盖安全清理策略、自动化脚本与环境最佳实践,告别“磁盘爆满”焦虑。(239字)
193 2
别再让Docker占满你的硬盘!一篇搞定docker system所有命令
|
23天前
|
人工智能 自然语言处理 监控
OpenClaw“养龙虾”保姆级教程:从零基础部署到进阶玩法与安全避坑指南
2026年,一款名为OpenClaw的开源AI智能体迅速走红全网,凭借红色龙虾样式的标识,被爱好者亲切称作“龙虾”,而部署、调教与使用OpenClaw的全过程,也被大家戏称为“养龙虾”。OpenClaw的核心理念是打造真正能落地执行任务的AI,它打破了传统AI仅停留在对话交互的局限,通过赋予模型操作系统、操控软件、读写文件、控制浏览器、执行代码等真实操作权限,让AI从“聊天助手”升级为可以自主干活的数字员工,能够理解自然语言指令并独立完成一系列自动化工作流。
558 7
|
23天前
|
运维 网络协议
KKCE 在线 Ping|实用网络连通性检测小工具
KKCE在线Ping是一款免安装、浏览器直用的网络检测工具,支持多节点同步测试域名/IP连通性、延迟与丢包率,直观定位卡顿、访问异常等基础网络问题,兼顾个人排查与运维需求。(239字)
400 1
|
24天前
|
人工智能 自然语言处理 机器人
[开源框架-实战]用 Hermes Agent 搭一个微信播报机器人
30 分钟,零 Python 代码,搭出一个每天早上 9 点把 GitHub Trending 推送到你微信的机器人。顺带把 Hermes 的 Skill、Gateway、Cron 四个招牌能力全用上。
483 8
|
24天前
|
人工智能 供应链 算法
从“小单困局”到供应链Agent:成本结构、博弈逻辑与人机协同的技术推演
本文剖析C2M服装供应链中“小单困局”的本质——切换成本在极小批量下不可摊销的数学必然。通过Agent集群实现成本透明化、智能拼单与品类感知,推动供应链从零和砍价转向正和协同。人机分工明确:AI做“数字包工头”,人当“关系架构师”。(239字)
|
4小时前
|
人工智能 缓存 弹性计算
阿里云服务器2核4G5M199元解析:独享型u1实例,性能、适用场景、购买和续费规则介绍
阿里云通用算力型u1实例(ecs.u1-c1m2.large)2核4G、5M带宽、80G ESSD Entry云盘,活动特惠价仅199元/年(官网价3498.36元),企业新老用户同享,续费同价至2027年3月31日,每人限购1台。该实例采用独享型架构,搭载Intel至强可扩展处理器,内网带宽1Gbit/s、收发包30万PPS、云盘IOPS 1万,性能稳定,适合企业官网、中小Web应用、轻量数据库及开发测试等场景。
|
2月前
|
人工智能 监控 网络协议
【App Service】常规排查 App Service 启动 Application Insights 无数据的步骤 (.NET版本)
本文详解Application Insights在Azure App Service中无日志数据的三大原因及排查方法:1)网络连通性(验证到AI端点的443端口访问);2)w3wp.exe进程是否成功加载AI模块;3)DLL冲突(检查并移除重复的Microsoft.ApplicationInsights等组件)。
156 10
|
24天前
|
机器学习/深度学习 人工智能 自然语言处理
Agent = Model + Harness:模型决定上限Harness 决定下限
Claude Code、Cursor等并非聊天界面,而是AI编码的“操作系统”——Harness。它决定模型能否稳定执行规则、调用工具、管理上下文与权限。模型定上限,Harness定下限。差异常源于Harness配置,而非模型本身。
329 5