Coder Social home page Coder Social logo

Comments (34)

 avatar commented on May 3, 2024 4

This whole thread blows my mind. With 15, maybe 20 years background in C++ I really will never get how a scripter's mind sticks together.

It's like demanding to be able to cook eggs using your door bell.

from uwebsockets.js.

aadityataparia avatar aadityataparia commented on May 3, 2024 3

Examples:
JS Exceptions -

      res.end({ user: 1 });
          ^

TypeError: res.end is not a function
    at /users (/Users/aaditya-taparia/Personal/sifrr-api-demo/routes/user.js:11:11)
Assertion failed: (err == 0), function uv_loop_delete, file ../deps/uv/src/uv-common.c, line 691.
[1]    75960 abort      node wsserver.js

Like other servers, I think it should not abort, rather should just show error in console and continue listening.

And when there is an error in underlying c code, there is no stack trace, and server just stops.

Server is running on localhost:2222
µWebSockets ill-use: Returning from a request handler without responding or attaching an abort handler is forbidden.
libc++abi.dylib: terminating
[1]    79105 abort      node wsserver.js

from uwebsockets.js.

 avatar commented on May 3, 2024 1

@musicformellons No this project is not the old "uws".

from uwebsockets.js.

porsager avatar porsager commented on May 3, 2024 1

Yeah, and be sure to have logging in place so that you have some clues for how to fix the error when time allows it ;)

from uwebsockets.js.

porsager avatar porsager commented on May 3, 2024 1

Ah, no I think that would be way out of scope, and there are already plenty of ways to handle this in a library/runtime agnostic way ;) - os service systems like systemd or node specific ones like pm2 or forever.

from uwebsockets.js.

porsager avatar porsager commented on May 3, 2024 1

@alexhultman Well being a first time user of a doorbell, maybe expecting eggs to be ready after the ring isn't so crazy ;)

from uwebsockets.js.

 avatar commented on May 3, 2024 1

Yeah anyways, glad we came to some understanding at least 👍

from uwebsockets.js.

 avatar commented on May 3, 2024

How do you mean? Error? There's no error?

Exceptions? You can catch them.

Errors? I don't know?

from uwebsockets.js.

musicformellons avatar musicformellons commented on May 3, 2024

I ran into this issue. Looks like uws errors and 'chokes' the container, which makes it hard to debug. So might be related.

from uwebsockets.js.

 avatar commented on May 3, 2024

@musicformellons That's not relevant here, you're using 2 year old code.

from uwebsockets.js.

 avatar commented on May 3, 2024

µWebSockets ill-use: Returning from a request handler without responding or attaching an abort handler is forbidden.
libc++abi.dylib: terminating

This is not an error, that's telling you you're using the lib in wrong ways. Read the text and fix. It should terminate if you have this issue. It's terminating the server because otherwise you will get strange bugs later on, and crash eventually.

The TypeError: res.end is not a function that's not completely correct, it should throw a different exception. I will check that. You probably need to do JSON.stringify({lalal})

from uwebsockets.js.

 avatar commented on May 3, 2024

This is what I get:

/home/alexhultman/uWebSockets.js/examples/HelloWorld.js:11
  res.end({val: 'Hello World!'});
      ^
Text and data can only be passed by String, ArrayBuffer or TypedArray.
node: ../deps/uv/src/uv-common.c:686: uv_loop_delete: Assertion `err == 0' failed.
Aborted (core dumped)

from uwebsockets.js.

 avatar commented on May 3, 2024

So what you want is basically a stack trace if a thrown error is not caught? Shouldn't an uncaught exception terminate the entire process?

from uwebsockets.js.

musicformellons avatar musicformellons commented on May 3, 2024

Ok. Actually it now works after downgrading to node 8, so that's nice. I am a bit lost in the 'maintenance for uws' discussion..., could I just 'make' this library and it might work with socket.io (sorry, I am a mere mortal who has this as a dependency)?!

from uwebsockets.js.

 avatar commented on May 3, 2024

There's really not that big of a difference compared to how Node.js throws and terminates:

/home/alexhultman/uWebSockets.js/examples/HelloWorld.js:6
const app = uWS./*SSL*/App({
            ^

ReferenceError: uWS is not defined
    at Object.<anonymous> (/home/alexhultman/uWebSockets.js/examples/HelloWorld.js:6:13)
    at Module._compile (internal/modules/cjs/loader.js:688:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:699:10)
    at Module.load (internal/modules/cjs/loader.js:598:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:537:12)
    at Function.Module._load (internal/modules/cjs/loader.js:529:3)
    at Function.Module.runMain (internal/modules/cjs/loader.js:741:12)
    at startup (internal/bootstrap/node.js:285:19)
    at bootstrapNodeJSCore (internal/bootstrap/node.js:739:3)

There's no need to have a stack trace in these cases, because.... there's no one. This is not a JS lib, so showing a large JS stack trace is impossible as you literally are being called directly from C++. It's not like Node.js where you have a big fat callstack in JS to show. How hard is it really to look at the error and fix the issue? It shows you the exact line and why it failed I don't get why this would not be enough?

from uwebsockets.js.

 avatar commented on May 3, 2024

Like other servers, I think it should not abort, rather should just show error in console and continue listening.

That would be insane. You're talking about behavior basically like Visual Basic 6.0 "on error resume next" basically "catch all exceptions and ignore them happily". That's nonsense.

from uwebsockets.js.

aadityataparia avatar aadityataparia commented on May 3, 2024

@alexhultman Can you please provide an example on how to catch the exceptions and prevent server from terminating?

from uwebsockets.js.

 avatar commented on May 3, 2024

Have you tried try catch? It works for me.

However,

The entire point of these exceptions IS to enforce the user to correct their code. This lib will only throw exceptions when you make invalid use of the library (such as giving it wrong types).

from uwebsockets.js.

 avatar commented on May 3, 2024

If I try catch my invalid type passed to res.end and print the exception I get this:

Listening to port 9001
Text and data can only be passed by String, ArrayBuffer or TypedArray.
Text and data can only be passed by String, ArrayBuffer or TypedArray.
Text and data can only be passed by String, ArrayBuffer or TypedArray.
Text and data can only be passed by String, ArrayBuffer or TypedArray.
Text and data can only be passed by String, ArrayBuffer or TypedArray.
Text and data can only be passed by String, ArrayBuffer or TypedArray.
Text and data can only be passed by String, ArrayBuffer or TypedArray.

It is obvious the program is wrong, it clearly states that you are passing wrong type.

from uwebsockets.js.

aadityataparia avatar aadityataparia commented on May 3, 2024

I am not against showing exceptions, that is obviously best. But what I am unsure about is, why abort server on exception, why not show exception and keep server running?

from uwebsockets.js.

 avatar commented on May 3, 2024

All exceptions in all languages ever made will terminate the process if not caught. Since you are not wrapping what you do wrong, in try catch, it will terminate. That's how exceptions work.

from uwebsockets.js.

 avatar commented on May 3, 2024

try {

res.end(my insane type);

} catch () {}

Now it won't terminate

from uwebsockets.js.

 avatar commented on May 3, 2024

I think you are mixing two different things here - JS exceptions vs. that one hard terminate thing. Consider the terminate thing a cash with a message.

Look at VideoStreamer example, that's how it should be written

from uwebsockets.js.

aadityataparia avatar aadityataparia commented on May 3, 2024

#32 (comment) This would mean I will have to wrap every res.end for every endpoint with a try catch block?

from uwebsockets.js.

 avatar commented on May 3, 2024

No. You're not listening to what I'm telling you.

  • Crash with reason = good.
  • Crash without reason and without deterministic behavior = bad.

from uwebsockets.js.

aadityataparia avatar aadityataparia commented on May 3, 2024

🙏

from uwebsockets.js.

aadityataparia avatar aadityataparia commented on May 3, 2024

And what I am saying is, crash with JS exception = bad

from uwebsockets.js.

porsager avatar porsager commented on May 3, 2024

@aadityataparia The key here is "unhandled/uncaught" exceptions. If you don't specifically handle the exception, the process should exit. The reasoning behind why this is the right thing to do has already been covered many times along with ways to handle it. Try to see if you can find writings about it by searching google - I did a quick search and this was the first I found - https://shapeshed.com/uncaught-exceptions-in-node/

#32 (comment) This would mean I will have to wrap every res.end for every endpoint with a try catch block?

No, this means that you should use the library as intended and only pass accepted types to res.end(). The solution for res.end({ user: 1 }) surely isn't to wrap it in try catch, but rather to fix the code eg. res.end(JSON.stringify({ user: 1 })).

When you set up your thing in production you will want to run your app with something that can ensure it is started again in the case an unhandled exception actually occurs (because none of us are perfect, and unexpected things can happen).

from uwebsockets.js.

aadityataparia avatar aadityataparia commented on May 3, 2024

Hmm.. makes sense, so I guess I should restart the server on an error.

from uwebsockets.js.

aadityataparia avatar aadityataparia commented on May 3, 2024

Yeah, logging is important. I was just hoping that restarting server or not exiting at all can be handled by uWS 🙇 Maybe not!

from uwebsockets.js.

 avatar commented on May 3, 2024

Okay but saw a board using nothing but mustard?

from uwebsockets.js.

 avatar commented on May 3, 2024

Fly to the moon using your dishwasher

from uwebsockets.js.

porsager avatar porsager commented on May 3, 2024

It'd make a great Disney cartoon!

from uwebsockets.js.

aadityataparia avatar aadityataparia commented on May 3, 2024

😂 Sorry for having such expectations!

from uwebsockets.js.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.