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

Fix #6958 #7596

Merged
merged 2 commits into from
May 10, 2021
Merged

Fix #6958 #7596

merged 2 commits into from
May 10, 2021

Conversation

PauloRSF
Copy link
Contributor

Description of change

When releasing a used query runner on postgres' driver, splice() was used without limiting the number of elements to be deleted, causing all the query runners to be removed, thus, preventing the driver from releasing them properly. So, the callback on

pool.end((err: any) => err ? fail(err) : ok());
was never called on node-postgres and the promise never resolved.

I created a test based on the issue's demo, which works now.

Fixes #6958

Pull-Request Checklist

  • Code is up-to-date with the master branch
  • npm run lint passes with this change
  • npm run test passes with this change
  • This pull request links relevant issues as Fixes #0000
  • There are new or updated unit tests validating the change
  • Documentation has been updated to reflect this change N/A
  • The new commits follow conventions explained in CONTRIBUTING.md

* 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
@@ -1051,7 +1051,10 @@ export class PostgresDriver implements Driver {
* Closes connection pool.
*/
protected async closePool(pool: any): Promise<void> {
await Promise.all(this.connectedQueryRunners.map(queryRunner => queryRunner.release()));
while (this.connectedQueryRunners.length) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you please explain why this change to while is needed? As I understand main motivation is to release them in sequence. If so, why its needed? Thanks!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because the .release() method of the query runners mutates the driver's connectedQueryRunners list, causing .map() to not iterate through all of them. I changed it to a while loop because it was the most obvious way i could think to ensure that all query runners got released and connectedQueryRunners was really empty before closing the pool 😅. If you have a better way to do it, let me know!

@AlexMesser AlexMesser merged commit 1310c97 into typeorm:master May 10, 2021
@AlexMesser
Copy link
Collaborator

thank you for contribution!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Promises never get resolved in specific cases
2 participants