-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
The server crashes if a promise with deferred handling rejects while another promise is trying to resolve #7857
Comments
Just FYI, your package-lock.json seems to have been created with some internal corporate npm mirror so that the URLs it tries to install are all from a private mirror. I'll delete the package-lock.json file when trying to reproduce but that might mean I get a different version of packages! |
I think this is basically working as intended, and it's not actually related to Apollo Server or GraphQL at all, just how Promises/async-await work in Node.JS. When you write this code:
there is no error handling connected to the Functions that call multiple Promise-returning functions should use a utility like |
To demonstrate that this is unrelated to AS or graphql, replace your server.mjs with:
Running this shows:
Note that you do not get the "Error caught from await" message here; this is the same issue, demonstrated without any use of |
thanks for the heads up, I replaced the repro with a public one |
@glasser I totally agree that uncaught exceptions should not exist in the app in the first place, but my concern comes from apollo-server being able to handle some uncaught exceptions, but crashing on others. As you noted, the example I provided has an uncaught exception:
because But this resolver is handled totally fine by apollo server:
Even though it's the same end result (uncaught exception). Maybe I'm missing something? It would be ideal if all unhandled exceptions were treated the same way by apollo-server. |
My point is that Apollo Server has nothing to do with this Promise. The very thing that (in a sense) makes Apollo Server/graphql-js aware that this Promise is connected to the result of executing your resolver in any way is the fact that it gets a As far as Node knows, your function may have just been:
because it never actually gets to the point of running your |
I see what the difference is now -- Thanks for explaining that to me, I will relay it. |
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Issue Description
If an unhandled error and/or promise rejection occurs in a resolver, the expectation is that the error will be caught by the Apollo Server and added to an
errors
array in the response.For example, this resolver:
should return something like this when queried:
However, "asynchronously handled" rejections (I'm not sure if my terminology is right) crash the server if the rejection occurs while another
await
is happening. Example:It looks like the promise has to be rejected while another await is still pausing execution. If the rejection happens faster than the await right after it, then the error is handled as expected.
For further info, here is what my terminal looks like (my code is in a file called "server.mjs", and I'm using the simple standalone example from the apollo-server README):
I also have in this submission a link to a repo with the reproduction.
I was also able to repro this with
.then
syntax instead of async/await. This resolver will also crash the server:I know that my repro code is not ideal -- promise rejections should be handled -- but I wouldn't expect this to take down the whole server. Could this be investigated?
Link to Reproduction
https://github.com/mfanegg/mock-apollo-server-for-issue-2
Reproduction Steps
npm i
node server.mjs
query { hello }
The text was updated successfully, but these errors were encountered: