Skip to content

fix setopt handling of timeouts#17571

Closed
icing wants to merge 7 commits intocurl:masterfrom
icing:conn-lifetime-fix-rounding
Closed

fix setopt handling of timeouts#17571
icing wants to merge 7 commits intocurl:masterfrom
icing:conn-lifetime-fix-rounding

Conversation

@icing
Copy link
Copy Markdown
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
Comment thread lib/url.c Outdated
Comment thread lib/url.c Outdated
@bagder
Copy link
Copy Markdown
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
Copy Markdown
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
Comment thread lib/setopt.c Outdated
@icing icing changed the title fix connection lifetime checks fix setopt handling of timeouts Jun 10, 2025
@icing
Copy link
Copy Markdown
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