Skip to content

Fix for SimplePool.setPoolSize() #3143 #3144

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

Closed
wants to merge 3 commits into from
Closed

Fix for SimplePool.setPoolSize() #3143 #3144

wants to merge 3 commits into from

Conversation

sergebg
Copy link
Contributor

@sergebg sergebg commented Jan 15, 2020

Original implementation exits from the loop if "available" collection is empty. That is not correct, because the number of allocated items can be less then pool size. And so it's OK if "item==null". It's just required to perform cleanup if "item!=null". Otherwise it's required to complete the loop until "delta!=0".

Resolves #3143

@pivotal-issuemaster
Copy link

@sergebg Please sign the Contributor License Agreement!

Click here to manually synchronize the status of this Pull Request.

See the FAQ for frequently asked questions.

@pivotal-issuemaster
Copy link

@sergebg Thank you for signing the Contributor License Agreement!

Copy link
Member

@artembilan artembilan left a comment

Choose a reason for hiding this comment

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

Thank you for contribution!

I'm not fully understand your fix.
Would you mind to explain it a bit different way?

Also consider to add your name to the @author list.

@@ -102,11 +102,9 @@ public synchronized void setPoolSize(int poolSize) {
break;
}
T item = this.available.poll();
if (item == null) {
this.permits.release();
Copy link
Member

Choose a reason for hiding this comment

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

You have stopped to release permits.
Why is that, please?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In this branch we need to call only acquire(). Original intent was to revert acquire if item==null. But this is absolutely incorrect. For example, if we have a new instance of pool, then "available" collection is empty. But setPoolSize() method should correctly update all structures. After calling setPoolSize(5) everything should contain 5. (permits==5, poolSize==5, and targetPoolSize==5). Of course, I am describing the situation when no objects were allocated. Please, check added test cases.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have added additional checks to test that "permits" field is correctly updated

import org.springframework.integration.test.util.TestUtils;

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.fail;
Copy link
Member

Choose a reason for hiding this comment

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

Please, do not rearrange imports order.
Consider to run gradlew check --parallel task to be sure that your changes follows our Checkstyle rules.
Also that will say you if your fix is valid against all the existing tests in the project.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sorry, I tried to keep imports untouched. I will revert this

@artembilan
Copy link
Member

@garyrussell , would you mind to take a look here?
Looks like you are more familiar with the code involved.

Thank you!

@garyrussell
Copy link
Contributor

@sergebg Good catch, thanks.

Some suggested test polishing here: garyrussell@3521f2a

@artembilan I can squash/merge after review of that commit.

Copy link
Member

@artembilan artembilan left a comment

Choose a reason for hiding this comment

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

LGTM after @garyrussell 's polishing.

Thank you both!

@artembilan artembilan added this to the 5.3.0.M1 milestone Jan 16, 2020
@garyrussell
Copy link
Contributor

Doing a local full build now; will merge after success.

@garyrussell
Copy link
Contributor

Merged as dba307a

@sergebg Thanks for the contribution!

@garyrussell
Copy link
Contributor

Cherry-picked to 5.2.x as 3850c7e

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.

SimplePool setPoolSize incorrectly updates internal fields
4 participants