Sunday, 3 November 2019

why is an http response being cut off on some devices?

I have a server that sends a large reply when you hit a specific GET endpoint. The server was working great until I moved it from my workstation to a raspberry pi model 4. Now the response is being cut off at 1325 bytes it does not matter what the response contains, it will always be chop off at that length. All other endpoints are working great (presumably because none writes data larger than 1325B). No errors are thrown and Insomnia (the rest client I use to test APIs) just hangs after the first 1325B. Browsers just say connection reset after some time.I tried the code on all my machines (workstation, gaming PC and a cheap laptop and it works on all of them). I tried it in glitch.com and it worked like a charm. I use node v13.0.1 in all my machines and v12.13.0 in glitch.com.I tried removing the headers for chunked transfer and content length but it is still broken.I am not using any framework (I am not allowed to use any). The pi is not behind a load balancer and the code for that endpoint looks like this: case "/search": { const text = url.parse(req.url, true).query.text; if (text.length > 4) { let results = await models.fullTextSearch(text);//This grabs 30 item IDs 64B each results = await results.map(async result=>{ result.PriceHistory = await models.getItemData(result.ID, 30); //This adds ~1MB/item return result; }); results = await Promise.all(results); results = JSON.stringify(results);//~30.5MB string res.writeHead(200, {'content-type': 'application/json', 'Access-Control-Allow-Origin': '*'}); res.write(results); res.end(); break; } res.writeHead(403, {'Content-Type': 'text/plain', 'Access-Control-Allow-Origin': '*'}); res.write("You made an invalid request!"); res.end(); break; }

Submitted November 03, 2019 at 04:00PM by Kran6a

No comments:

Post a Comment