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

Use connection pause/resume to prevent kill race condition #7

Conversation

martinmacko47
Copy link
Owner

No description provided.

@@ -1051,6 +1051,68 @@ module.exports = function (knex) {
});
});

it('.timeout(ms, {cancel: true}) should not cancel subsequent queries in a transaction if timeouted query completes while being cancelled', async function () {
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 test will fail without connectionToKill.pause()/resume() in Client_MySQL.cancelQuery() method. The test simulates a race-condition when the timeouted query manages to complete while we are trying to kill it. It is simulated by slowing down Client_MySQL.acquireRawConnection() method.

The current behaviour without connectionToKill.pause()/resume():

current

Fixed behaviour without the race condition with connectionToKill.pause()/resume():

expected

Btw, note that query B has no timeout, to make sure it won't timeout while waiting in the queue.

@@ -179,6 +180,7 @@ class Client_MySQL extends Client {
if (conn.__knex__disposed) {
this.logger.warn(`Connection Error: ${conn.__knex__disposed}`);
}
connectionToKill.resume();

Choose a reason for hiding this comment

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

minor tweak: this could be run before connection destroy, so working connection will continue to work earlier

Copy link
Owner Author

Choose a reason for hiding this comment

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

Moved in f1a3d8a

…se-all-timeout-error+dequeue-in-driver+pause-resume

Conflicts:
	test/integration/query/additional.js
@martinmacko47 martinmacko47 merged commit 9e7c1db into promise-all-timeout-error+dequeue-in-driver Apr 28, 2021
@martinmacko47 martinmacko47 deleted the promise-all-timeout-error+dequeue-in-driver+pause-resume branch April 28, 2021 12:04
martinmacko47 added a commit that referenced this pull request Apr 28, 2021
* Use connection pause/resume to prevent kill race condition

* Move connection resume before destroy raw connection
Conflicts:
	lib/dialects/mysql/index.js
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants