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.

Promises never get resolved in specific cases

See original GitHub issue

Issue type:

[x] bug report [ ] feature request [ ] documentation issue

Database system/driver:

[ ] cordova [ ] mongodb [ ] mssql [ ] mysql / mariadb [ ] oracle [x] postgres [ ] cockroachdb [ ] sqlite [ ] sqljs [ ] react-native [ ] expo

TypeORM version:

[ ] latest [x] @next [ ] 0.x.x (or put your version here)

Steps to reproduce or a small repository showing the problem:

Sometimes promises just never resolve. At first I thought it might be related with running scripts with ts-node, however even when using pure JS the issue is the same.

The freeze always happens when I try to perform a query after another query was performed without closing the connection. Here closing and re-connecting seems to avoid the bug, however I had another case where I tried saving an entity to a repository after performing a raw query and it also froze on the await repository.save(...) method, re-connecting did not fix it.

Here’s a code snippet:

const createConnection = require("typeorm").createConnection;


(async () => {
    const con = await createConnection();
    await con.createQueryRunner().query(`SELECT 1 as foo`);
    // re-connecting would work here...
    // await con.close();
    // await con.connect();
    await con.createQueryRunner().query(`SELECT 1 as foo`);
    console.log(1);
    await con.close(); // freezes here
    console.log(2); // this is never reached
})();

The actual contents of the raw query do not seem to matter, it happens every time. The problem is probably related to raw queries since the problem didn’t happen with repositories (until doing a raw query once, after that it does).

Also tried it without await by using .then(...) callbacks, same outcome.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:3
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
brinzicommented, Jul 8, 2021

This still happens on 0.2.34

0reactions
imnotjamescommented, Jul 8, 2021

This still happens on 0.2.34

I can’t replicate it. Can you open a new issue with info on how you’re replicating this issue

Read more comments on GitHub >

github_iconTop Results From Across the Web

What happens if you don't resolve or reject a promise?
A promise is just an object with properties in Javascript. There's no magic to it. So failing to resolve or reject a promise...
Read more >
Promise.resolve() - JavaScript - MDN Web Docs
The Promise.resolve() method "resolves" a given value to a Promise. ... eventual fulfillment value of the promise will never be thenable.
Read more >
Error handling with promises - The Modern JavaScript Tutorial
In the task an error is thrown form inside the promise and promise is never settled neither with a resolve nor reject. The...
Read more >
A deep-dive into promise resolution with objects including a ...
If you resolve a promise with an object including a then property which is not a function, the promise is resolved with the...
Read more >
JavaScript Promise Tutorial – How to Resolve or Reject ...
In most cases, a promise may be used for an asynchronous operation. However, technically, you can resolve/reject on both synchronous and ...
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