Skip to content

Fixed timeout when acquiring connection from the pool #330

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

Merged
merged 1 commit into from
Feb 26, 2018

Conversation

lutovich
Copy link
Contributor

Previously it was possible for timeout to kick in after connection acquisition promise is resolved, but before timeout itself is cleared.

Pseudocode would be:

const acquisitionTimeout = xxx;

const f1 = () => {/* fail and clear the acquisition attempt */};
const acquisitionTimeoutId = setTimeout(f1, acquisitionTimeout);

const f2 = () => clearTimeout(acquisitionTimeoutId);
connectionAcquisitionPromise.then(f1);

This code allows connectionAcquisitionPromise to get resolved and f1 to get executed before f2. It is possible because installed callbacks are only scheduled, not executed when promise is resolved.

This PR fixes the problem by moving clearTimeout to the place that resolves the acquisition request, i.e. Pool#release() call.

Fixes #304

Previously it was possible for timeout to kick in after connection
acquisition promise is resolved, but before timeout itself is cleared.

Pseudocode would be:

```
const acquisitionTimeout = xxx;

const f1 = () => {/* fail and clear the acquisition attempt */};
const acquisitionTimeoutId = setTimeout(f1, acquisitionTimeout);

const f2 = () => clearTimeout(acquisitionTimeoutId);
connectionAcquisitionPromise.then(f1);
```

This code allows `connectionAcquisitionPromise` to get resolved and `f1`
to get executed before `f2`. It is possible because installed callbacks
are only scheduled, not executed when promise is resolved.

This commit fixes the problem by moving `clearTimeout` to the place
that resolves the acquisition request, i.e. `Pool#release()` call.
@lutovich lutovich requested a review from ali-ince February 23, 2018 17:43
Copy link
Contributor

@ali-ince ali-ince left a comment

Choose a reason for hiding this comment

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

👍

@ali-ince ali-ince merged commit 5d2101f into neo4j:1.5 Feb 26, 2018
@lutovich lutovich deleted the 1.5-pool-acquire-fix branch February 26, 2018 12:54
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.

2 participants