Configure OkHttp connection pool with 55s keep-alive#52
Merged
AaronAtDuo merged 1 commit intoduosecurity:mainfrom Mar 19, 2026
Merged
Conversation
AaronAtDuo
approved these changes
Mar 19, 2026
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Description
Resolves #51
Duo's services close the remote side of a connection after about one minute of idle. OkHttp defaults to a keep-alive timeout of 5 minutes and does not check for closed connections until that timeout. As a result, any connection left in the pool will sit in a
CLOSE-WAITstate for ~4 minutes before it is fully closed and evicted.This change updates the OkHttp connection pool to use a keep-alive of 55 seconds so that we cleanly close those connections before they get stale.
Motivation and Context
There is no advantage to trying to maintain an idle connection to Duo's services for longer than 60 seconds, since the server-side will sever the connection. The connection pool still works properly with a longer timeout, but in times of low traffic, can end up leaving sockets sitting in
CLOSE-WAITfor several minutes. It is better hygiene to close these out sooner.How Has This Been Tested?
Ran the
duo-examplespringboot app, authing several times, and then watching the socket state withlsof -p <springboot pid> | grep TCP | grep ec2.Before this change, we can see the socket to Duo's service entering
CLOSE-WAITafter ~1 minute of idle time and then get completely closed after another ~4 minutes.After this change, we can see the socket to Duo's service get completely closed after ~55 seconds of idle time and never sits in the
CLOSE-WAITstate.Types of Changes