SignalR连接引发网关超时及STJ在ARM64实例栈溢出问题
调试多日仍无头绪,搭建的集成SignalR的ASP.NET 6 API本地运行完全正常,但部署到搭载Nginx的AWS t4g.small(ARM64架构)服务器后出现异常:WebSocket连接建立后,同一页面的任意API调用都会导致Nginx返回网关超时,SignalR断开连接约1分钟后重连,API调用再次失败并触发网关超时。
Nginx日志信息
2022/09/24 16:18:30 [error] 41453#41453: *17989 connect() failed (111: Connection refused) while connecting to upstream, client: 10.30.4.89, server: test.SNIP.com, request: "GET /api/h?access_token=SNIP HTTP/1.1", upstream: "http://127.0.0.1:5010/api/h?access_token=SNIP", host: "test.SNIP.com"
2022/09/24 16:25:31 [error] 41453#41453: *18087 connect() failed (111: Connection refused) while connecting to upstream, client: 10.30.4.89, server: test.SNIP.com, request: "POST /api/start HTTP/1.1", upstream: "http://127.0.0.1:5010/api/start", host: "test.SNIP.com", referrer: "https://test.SNIP.com/arena"
曾怀疑是Kestrel/SignalR拒绝请求,但未找到相关日志,已将Nginx配置精简至最简仍未解决。
更新:通过journalctl日志发现,System.Text.Json(STJ)在t4g.small实例上触发栈溢出异常。以下组合可正常运行:
- 保留STJ,改用AMD架构的t3a.small实例
- 改用Newtonsoft.Json搭配t4g.small实例
但STJ+t4g.small组合在处理Dictionary<string, object>时会失败。
相关JSON结构
{ "action": "Battle", "data": { "Level": 10 } }
实体类代码
public sealed class Action { public int Id { get; set; } public ActionTypes ActionType { get; set; } // enum public int UserId { get; set; } public Dictionary<string, string> Data { get; set; } = new(); }
内容的提问来源于stack exchange,提问作者Phill

