Skip to content

fix setopt handling of timeouts #17571

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 7 commits into from

Conversation

icing
Copy link
Contributor

@icing icing commented Jun 10, 2025

Change the internal timeout fields to type timediff_t and check validity when setting the option with common helper functions for these timeouts. Cap too large values silently to TIMEDIFF_T_MAX.

The checks for a connection being "too long idle" or "too old" were rounding down the elapsed time to seconds before comparing to the configured max values. This caused connections to be reused for up to 999ms longer than intended.

Fixes sporadic failures of test1542 on platforms where "sleep(2)" returnes before 2 full seconds on the internal clock had passed.

Reporter: Christian Weisgerber via curl-library mailing list

The checks for a connection being "too long idle" or "too old"
where rounding down the elapsed time to seconds before comparing
to the configured max values. This caused connections to be reused
for up to 999ms longer than intended.

Change the compares to scale the configured seconds up to ms, so
connection will properly be "too old" 1 ms after the coonfigured
values.

Fixes sporadic failures of test1542 on platforms where "sleep(2)"
returnes before 2 full seconds on the internal clock where passed.

Reporter: Christian Weisgerber via curl-library mailing list
@icing icing changed the title fix connectin lifetime checks fix connection lifetime checks Jun 10, 2025
@bagder
Copy link
Member

bagder commented Jun 10, 2025

We can fix these by capping the values already in setopt_long() if set higher than some threshold.

@icing
Copy link
Contributor Author

icing commented Jun 10, 2025

setopt_long

Maybe make the internal fields a timediff_t and convert in setopt?

@icing icing requested a review from bagder June 10, 2025 09:23
@icing icing changed the title fix connection lifetime checks fix setopt handling of timeouts Jun 10, 2025
@icing
Copy link
Contributor Author

icing commented Jun 10, 2025

A little bit broader brush stroke in this PR. Have a common handling of most timeout values in setopt and change the timeout vars to timediff_t.

Interestingly, there are platforms where timediff_t is larger than long. More pitfalls here than originally expected.

@icing icing requested a review from bagder June 10, 2025 15:16
@bagder bagder closed this in e39b8c4 Jun 11, 2025
denandz pushed a commit to denandz/curl that referenced this pull request Jun 21, 2025
The checks for a connection being "too long idle" or "too old" where
rounding down the elapsed time to seconds before comparing to the
configured max values. This caused connections to be reused for up to
999ms longer than intended.

Change the compares to scale the configured seconds up to ms, so
connection will properly be "too old" 1 ms after the coonfigured values.

Fixes sporadic failures of test1542 on platforms where "sleep(2)"
returnes before 2 full seconds on the internal clock where passed.

Reported-by: Christian Weisgerber
URL: https://curl.se/mail/lib-2025-06/0004.html
Closes curl#17571
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants