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 a connection pool error. #419

Merged
merged 1 commit into from
Jun 4, 2019

Conversation

mikkokar
Copy link
Contributor

Summary

This PR fixes a little mistake in a SimpleConnectionPool that may allow more than allowed connections to be created.

Root Cause

A borrowCount was incorrectly used check if we need to create a new connection or not. But there is a problem:

  • A connection establishment is an asynchronous operation, and borrowCount is incremented only after the establishment has completed, and the new connection is handed out to a pool consumer.

  • Due to TCP 3 way handshake and a potential SSL handshake there is a considerable time lag between start of the connection establishment and borrowCount being incremented.

  • Extra connections can get created within this time window.

Fix

Add an extra counter to track the number of connections under establishment. Only trigger a connection establishment if borrowCount + connectionsUnderEstablishment is less than maximum allowed.

@mikkokar mikkokar requested review from kvosper and dvlato May 30, 2019 14:31
@mikkokar mikkokar merged commit d499873 into ExpediaGroup:master Jun 4, 2019
@mikkokar mikkokar deleted the fix-connection-pool-error branch June 4, 2019 07:03
dvlato pushed a commit that referenced this pull request Jul 3, 2019
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