Web 套接字关闭时的 Heroku H15 错误 [英] Heroku H15 Error on web socket close

查看:14
本文介绍了Web 套接字关闭时的 Heroku H15 错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 Go 服务作为 Heroku 上的网络套接字服务器.客户端每 20 秒 ping 服务器一次,它似乎保持连接打开.问题是当套接字连接关闭时,Heroku 路由器会抛出 H15 错误,认为请求花费了太多时间.例如,如果 Web 套接字连接已打开 300 秒,Heroku 日志将显示:

I have a Go service serving as a web socket server on Heroku. The client pings the server every 20 seconds and it seems to keep the connection open. The problem is that when the socket connection is closed, Heroku router throws H15 error thinking that the request took too much time. For example, if web socket connection has been open for 300 seconds, Heroku log would show:

....H15....dyno=web.1 connect=1ms service=300000ms status=503 bytes=147….

….H15…. dyno=web.1 connect=1ms service=300000ms status=503 bytes=147….

有人遇到过这种情况吗?

Anyone has experienced this?

推荐答案

是的!我经历过这种情况,经过一些深度调试后,我得出结论,这只是 Heroku 路由器引擎中的误报".我的调试是这样的:

yes! I have experienced that situation and after some deep debugging, I came to the conclusion that this is just a "false positive" in the Heroku Router engine. My debugging went like this:

  1. 在客户端和 Heroku 上运行的 WebSocket 服务器之间创建 WebSocket 连接.
  2. 如果您使用 socket.io 或类似的库,它很可能会在将协议切换到 WebSocket 之前建立 HTTP 轮询连接.(您可以在 Heroku 路由器日志中看到这些 GET/POST 请求).
  3. 使用 WebSocket 协议建立连接后,客户端将通过发送心跳保持连接(实际上服务器也可以这样做).最初,您不会在 Heroku 路由器日志中看到此请求,因为它仍处于挂起状态(它处于打开状态,每隔几秒发送一次数据包,即心跳).您可以使用 Chrome DevTools 的网络"标签对此进行监控.
  4. 心跳阻止 Heroku 路由器终止请求,因为每次在客户端和服务器之间传输几个字节时,Heroku 路由器超时计时器(55 秒)已重置.
  5. 但是,每当您的客户端关闭连接(即:关闭浏览器选项卡、刷新页面、断开互联网连接等);Heroku 路由器检测到请求被终止并且(这里是我基于调试的猜测)因为请求是待处理",它的反应就好像它处于空闲状态 X 毫秒,其中 X 是从收到请求到关闭请求的时间,你会看到这样的日志:service=79859ms status=101
  1. Create a WebSocket connection between the client and the WebSocket server running on Heroku.
  2. If you're using socket.io or a similar library it will most likely establish an HTTP polling connection before switching protocols to WebSocket. (You can see these GET/POST requests in the Heroku Router logs).
  3. Once the connection is established using the WebSocket protocol, the client will keep it alive by sending a heartbeat (actually the server can do this too). Initially, you won't see this request in the Heroku Router logs because it's still pending (it's open and sending packages of data every few seconds, the heartbeat). You can monitor this by using the Chrome DevTools Network tab.
  4. The heartbeat prevents Heroku Router from terminating the request, since every time a few bytes are transferred between the client and the server the Heroku Router timeout timer (55secs) is reset.
  5. However, whenever your client closes the connection (ie: closes the browser tab, refreshes the page, disconnects from the internet, etc); the Heroku Router detects the request being terminated and (here comes is my guess based on debugging) because the request was "pending" it reacts as if it was idle for X amount of milliseconds, where X is the time from when the request was received until it was closed, that's when you see logs like this: service=79859ms status=101

结论:每当您的客户端应用程序终止 WebSocket 连接时,Heroku 路由器都会记录错误 15 行,这在 X 毫秒内运行良好.因此,在许多情况下,可能只是用户离开了您的应用.

As a conclusion: Heroku Router will log an Error 15 line whenever your client app terminates a WebSocket connection which was working perfectly fine for X amount of milliseconds. So, in many cases, it can be just users leaving your app.

我希望这对人们有所帮助,希望你们可以少担心一件事:)

I hope this helps people and that you guys can go to sleep with one less thing to worry about :)

这篇关于Web 套接字关闭时的 Heroku H15 错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆