-
Notifications
You must be signed in to change notification settings - Fork 330
Add configurable idle connection timeout (ADO #39970) #4295
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
Open
priyankatiwari08
wants to merge
5
commits into
dotnet:main
Choose a base branch
from
priyankatiwari08:feature/idle-connection-timeout-pr1
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
126f16a
Add configurable idle connection timeout (ADO #39970)
priyankatiwari08 2a94926
Address Copilot review feedback on #4295
priyankatiwari08 93ab7ee
Address PR #4295 inline review feedback
priyankatiwari08 dd30ce7
Address PR review: default IdleTimeout=300, remove synonym, drop tran…
priyankatiwari08 b3a7b12
Address PR #4295 review feedback on idle timeout behavior
priyankatiwari08 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1028,7 +1028,7 @@ private bool TryGetConnection(DbConnection owningObject, uint waitForMultipleObj | |
| Interlocked.Decrement(ref _waitCount); | ||
| obj = GetFromGeneralPool(); | ||
|
|
||
| if ((obj != null) && (!obj.IsConnectionAlive())) | ||
| if ((obj != null) && (!obj.IsConnectionAlive() || IsIdleExpired(obj))) | ||
| { | ||
| SqlClientEventSource.Log.TryPoolerTraceEvent("<prov.DbConnectionPool.GetConnection|RES|CPOOL> {0}, Connection {1}, found dead and removed.", Id, obj.ObjectID); | ||
| DestroyObject(obj); | ||
|
|
@@ -1207,7 +1207,7 @@ private DbConnectionInternal GetFromTransactedPool(out Transaction transaction) | |
| throw; | ||
| } | ||
| } | ||
| else if (!obj.IsConnectionAlive()) | ||
| else if (!obj.IsConnectionAlive() || IsIdleExpired(obj)) | ||
|
priyankatiwari08 marked this conversation as resolved.
Outdated
|
||
| { | ||
| SqlClientEventSource.Log.TryPoolerTraceEvent("<prov.DbConnectionPool.GetFromTransactedPool|RES|CPOOL> {0}, Connection {1}, found dead and removed.", Id, obj.ObjectID); | ||
| DestroyObject(obj); | ||
|
|
@@ -1329,13 +1329,27 @@ private void PutNewObject(DbConnectionInternal obj) | |
|
|
||
| SqlClientEventSource.Log.TryPoolerTraceEvent("<prov.DbConnectionPool.PutNewObject|RES|CPOOL> {0}, Connection {1}, Pushing to general pool.", Id, obj.ObjectID); | ||
|
|
||
| // Stamp the idle-since timestamp immediately before placing the connection on the idle stack | ||
| // so that idle-expiry checks on later retrieval can decide whether it has sat unused too long. | ||
| obj.MarkPooledIdle(); | ||
|
priyankatiwari08 marked this conversation as resolved.
Outdated
|
||
| _stackNew.Push(obj); | ||
| _waitHandles.PoolSemaphore.Release(1); | ||
|
|
||
| SqlClientDiagnostics.Metrics.EnterFreeConnection(); | ||
|
|
||
| } | ||
|
|
||
| /// <summary> | ||
| /// Returns true when the supplied connection has been sitting idle in the pool longer than the | ||
| /// configured <see cref="DbConnectionPoolGroupOptions.IdleTimeout"/>. Returns false when idle timeout | ||
| /// is disabled (zero). | ||
| /// </summary> | ||
| private bool IsIdleExpired(DbConnectionInternal obj) | ||
| { | ||
| TimeSpan idleTimeout = PoolGroupOptions.IdleTimeout; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we can check the switch value here. |
||
| return idleTimeout != TimeSpan.Zero && DateTime.UtcNow > obj.IdleSinceUtc + idleTimeout; | ||
| } | ||
|
|
||
| public void ReturnInternalConnection(DbConnectionInternal obj, DbConnection owningObject) | ||
| { | ||
| Debug.Assert(obj != null, "null obj?"); | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.