Skip to content
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

Promises never get resolved in specific cases #6958

Closed
shiro opened this issue Oct 21, 2020 · 5 comments · Fixed by #7596
Closed

Promises never get resolved in specific cases #6958

shiro opened this issue Oct 21, 2020 · 5 comments · Fixed by #7596
Labels
bug next An issue related to the next branch

Comments

@shiro
Copy link

shiro commented Oct 21, 2020

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.

@hardboiled
Copy link

Stupid question and probably not the issue, but still curious: does putting a semi-colon in your queries change anything?

await con.createQueryRunner().query(`SELECT 1 as foo;`);
await con.createQueryRunner().query(`SELECT 1 as foo;`);

@shiro
Copy link
Author

shiro commented Oct 21, 2020

No, doesn't change anything.

@imnotjames imnotjames added next An issue related to the next branch bug labels Oct 21, 2020
@ydhnwb
Copy link

ydhnwb commented Jan 15, 2021

I have the same problem, sometimes it is work, but sometimes it just freeze there, not returning anything.

@PauloRSF PauloRSF mentioned this issue Apr 27, 2021
7 tasks
AlexMesser pushed a commit that referenced this issue May 10, 2021
* fix: Promises never get resolved in specific cases (#6958)

* Limit the number of query runners to remove when releasing one of them
* Add while loop to release all items on the connected query runners list

Closes #6958

* test: Create test for github issue #6958
@pxr64
Copy link

pxr64 commented Jul 8, 2021

This still happens on 0.2.34

@imnotjames
Copy link
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug next An issue related to the next branch
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants