uNetworking / uWebSockets.js

μWebSockets for Node.js back-ends :metal:
Apache License 2.0
7.84k stars 569 forks source link

Request hangs and/or never gets responded #1089

Closed dalisoft closed 1 month ago

dalisoft commented 1 month ago

Issue

Request hanging without response but it should work as expected

Code

import uWS from 'uWebSockets.js';

const uws_app = uWS.App();

uws_app.get('/test', async (res, req) => {
  res.onAborted(() => {
    res.aborted = true;
    console.log('on aborted');
  });

  req.method = req.getCaseSensitiveMethod();
  req.path = req.getUrl();
  req.headers = {};

  await new Promise((resolve) => setTimeout(resolve, 5000));

  return res.cork(() => res.end('success'));
});

uws_app.listen(4000, (listen) =>
  listen ? console.log('Listening at 4000') : null
);

Test

curl http://localhost:4000/test --output -
dalisoft commented 1 month ago

@e3dio For me it does not work. Can you attach an example video please like below? Thank you

https://github.com/user-attachments/assets/fb5af302-605e-4fe3-a1cd-e0628d18c32d

e3dio commented 1 month ago

Looks like you have not done enough troubleshooting yet, you are running multiple servers in same test and not showing the full code that is running, you have done no basic elimination of possible issues by removing code until something works, add more logging, everything works fine for me

dalisoft commented 1 month ago

Which OS are you running @e3dio?

e3dio commented 1 month ago

Linux - Node v22.6.0 - uWS.js v20.47.0

dalisoft commented 1 month ago

Seems problem on my macOS, it works on Linux on my machine too

uNetworkingAB commented 1 month ago

I ran this on M1, works. But are you sure it'a not just curl timing out and closing? Your video shows that it works, it does report correctly but probably curl that closes.

e3dio commented 1 month ago

Doesn't help that @dalisoft does not show all code of test, doing something like import { setTimeout } from 'node:timers/promises' at the top would give the results shown in video. Minimizing the test to something that works would pinpoint the exact issue, but basic troubleshooting steps were not followed, he just gave up instead

dalisoft commented 1 month ago

@e3dio The code provided here also not worked so problem not about troubleshooting, it’s about OS.

on Linux that code worked (even code like video).

Now testing code on Linux and it works, i am closed issue after see it works on Linux

dalisoft commented 1 month ago

@uNetworkingAB i got it working on Linux, Ubuntu 20.04. Seems something wrong with my Mac, so i will troubleshoot why it does not work on my Mac next days. Thank you for note about curl, i keep in mind in future

uNetworkingAB commented 1 month ago

You can use DTrace

dalisoft commented 1 month ago

I will use dtrace to debug. My problem was either with VSCode or macOS itself, anyway, after re-installing (from scratch) everything works fine now