Heroku上的服务器请求中断(H18) [英] Server Request Interrupted (H18) on Heroku

查看:98
本文介绍了Heroku上的服务器请求中断(H18)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Heroku的支持不是很有帮助(除了添加更多日志会有所帮助"之类的提示),因此让我在这里尝试.

The Heroku support isn't very helpful (except the tips like "adding more logs would help") so let me try here.

我们最近遇到了很多503.使用curl再现503非常容易:

We are encountering a lot of 503 recently. It's super easy to reproduce the 503 using curl:

curl —limit-rate=100 -s -X POST https://our.server.com/some/endpoint?[1-100] \
   --header 'Content-Type: multipart/form-data; boundary=---------BOUNDARY' \
   --data-binary @test.txt

如果 test.txt 足够大(例如1Kb),Heroku将很快触发503(顺便说一句,它甚至不需要是多部分表单数据).因此,我假设存在某种DDoS保护,即使在我们简陋的Node.js + Express应用程序以及我的同事的Node应用程序上也会发生这种情况.

If the test.txt is large enough (e.g. 1Kb), the Heroku will trigger 503 soon (btw. it doesn't even need to be a multipart form data). So I assume there is some kind of DDoS protection as this happens even on our dead-simple Node.js + Express app along with the Node apps of my colleagues.

如果是这种情况,有什么办法可以使503错误静音?

If that's the case - is there any way to silent the 503 errors?

这些最近开始使我们烦恼,因为我们的一个端点现在希望包含多部分数据(但我会重复一遍-这不必是多部分数据,它也可以在application/json中重现).如果身份验证失败-我们发送401.似乎不足以关闭多部分流?

These started to annoy us lately, as one of our endpoints expect the multipart-data now (but I'll repeat - this doesn't have to be a multipart-data it is also reproducible with application/json). If authentication fails - we send the 401. Seems that is not enough to close the multipart stream?

我了解到的是Heroku缓冲多部分流,导致某种类型的缓冲区溢出,并导致->触发503.

What I understand is that Heroku buffers the multipart stream, leading to some kind of buffer overflow and in result -> triggering the 503.

代码:

(...)
const router = require('express').Router()
// We are getting `401` for the first 10-100 requests, then -> 503 hopes in
router.post('/some/endpoint', async function (req, res, next) {
   return res.status(401).send('Test')
})
app.use('/', router)
(...)

推荐答案

结果表明,失败的原因是非常老的

It came out that the reason for the failure was a very old Node.js bug (I got the link from Taylor from Heroku support). Apparently, the is no fix for that yet except to fully handle the incoming stream.

这篇关于Heroku上的服务器请求中断(H18)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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