Server Request Interrupted (H18) on Heroku

假装没事ソ 提交于 2020-01-24 20:45:10

问题


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

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

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.

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

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?

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

Code:

(...)
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)
(...)

回答1:


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.



来源:https://stackoverflow.com/questions/56498812/server-request-interrupted-h18-on-heroku

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!