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

feat: close connections that exceeds opts.idleTimeout #159

Merged
merged 3 commits into from
Aug 17, 2021

Conversation

cyjake
Copy link
Owner

@cyjake cyjake commented Aug 16, 2021

fixes #148, closes #60 with a mocked Pool and Connection for sqlite driver

@cyjake cyjake requested a review from JimmyDaddy August 16, 2021 15:10
@cyjake cyjake force-pushed the feat-close-idle-connections branch from 6c14bd4 to 48476a1 Compare August 16, 2021 15:13
fixes #148, closes #60 with a mocked Pool and Connection for sqlite driver
@cyjake cyjake force-pushed the feat-close-idle-connections branch from 48476a1 to 6309822 Compare August 17, 2021 01:45
src/drivers/sqlite/index.js Show resolved Hide resolved
return connection;
}
await new Promise(resolve => queue.push(resolve));
return await this.getConnection();
Copy link
Collaborator

Choose a reason for hiding this comment

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

This may cause infinite loop in some edge case. How about set a waiting timeout, then throw error while waiting timeout and no connection available

Copy link
Owner Author

Choose a reason for hiding this comment

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

This is the default behavior that the mysql client supports, when connection pool is drained, wait for connection being released.

this.emit('release', connection);

const { queue } = this;
while (queue.length > 0) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

the queue use for what? It seems store resolve functions.

Copy link
Owner Author

Choose a reason for hiding this comment

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

It's a simple hack for referencing hanging awaits in getConnection, when new connection is available, begin dequeue continue previous blocking jobs.

src/drivers/mysql/index.js Show resolved Hide resolved
@JimmyDaddy JimmyDaddy merged commit 837a266 into master Aug 17, 2021
@cyjake cyjake deleted the feat-close-idle-connections branch August 17, 2021 12:34
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.

idleTimeout should be added to close idle connections Can we support pool for sqlite?
2 participants