question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Resolvers keep running even after one of them throws/rejects - consider Promise.allSettled?

See original GitHub issue

Hi, I recently came across this issue while trying to create a DB transaction per request.

The reason for using a DB transaction per request (which means 1 connection per client) is to keep the returned data consistent (ISOLATION READ COMMITED) as with increased traffic some inconsistencies started to occur on certain queries.

The second reason is having more control over the db connections to support load balancing with dynamic number of read replicas (as the only available solution unfortunately does not support connection pool). However I suppose this can be solved with some effort.

The problem is that when one of the resolvers fails with error (which is not a casual case but happens sometimes), other resolvers keep running. However I need to release the db connection before I send the response which sometimes happens before the rest of resolvers finishes (most of them are data loaders which makes the problem more obvious as the default behaviour is to wait for the next tick until the batch operation runs).

The problem could be resolved by using Promise.allSettled instead of Promise.all. I can’t come up with any problem this change could cause except longer time till response in case of error.

Can you please correct me if I’m mistaken or consider this change? Or maybe transactional processing of resolvers is a bad idea in general (although I don’t see any reason except the performance gain from using multiple connections per request)

Thanks a lot!

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:1
  • Comments:8 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
IvanGoncharovcommented, Apr 4, 2021

@olsavmic I think it’s a more general issue than DB transactions since it will affect any resources with reference counting. Also, it can potentially DDoS problem, if you can find a request that fails fast but provokes a lot of memory allocation referenced by long-running resolvers you can run out of memory on the server.

But we need to be extra careful with execute code to not affect performance or correctness. So let’s postpone this fix until we finish TS conversion and release it in the upcoming 16.0.0.

0reactions
charsleysacommented, Feb 24, 2022

We ran into this issue and it was causing problems with our dependency injection as we didn’t expect the behaviour of graphql to be continue processing after returning an error result.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Promise.allSettled() - JavaScript - MDN Web Docs
allSettled () method takes an iterable of promises as input and returns a single Promise . This returned promise fulfills when all of...
Read more >
Better handling of rejections using Promise.allSettled()
all() is really useful. The problem is though, that if one of those Promises fails/rejects, all the function calls will still happen, but...
Read more >
Does Promise.allSettled preserve the original order in the ...
Yes, it is guaranteed. The steps are described in the specification. On each iteration over the passed iterable, it does.
Read more >
JavaScript Promises: race, all, allSettled, and then
With promise methods like Promise.all() — which takes an array of promises ... You (the developer working on this) need to think about...
Read more >
Understanding Promise.allSettled() - JavaScript in Plain English
allSettled () method to execute multiple asynchronous calls. ... Even though the first promise takes more time to resolve than the second one,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found