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

Specify how to disable timeouts #4069

Merged
merged 16 commits into from
Mar 5, 2024
Merged

Conversation

dridi
Copy link
Member

@dridi dridi commented Feb 29, 2024

Following consensus, this patch series formalizes several things:

  • NAN means that a timeout is not set (only possible in VCL, parameters must have a default value)
  • it is possible to unset timeout variables in VCL
    • they are unset by default (it was already the case)
    • they fall back to the relevant parameter when read (it was already the case for sess.*timeout*)
  • INFINITY disables a timeout
    • it translates to VRT_DECIMAL_MAX in VCL
    • in the poll(2) case it translates to -1 (aka INFTIM)
    • in the setsockopt(2) case it translates to a zero timeval
    • a zero timeout for setsockopt(2) translates to a 1us timeout (should it be 1ms?)
  • a new duration tweak is added for parameters (inconsequential for designated parameters)
  • the existing timeout tweak can now take a special value "never"
  • bereq timeouts have two levels of fallback
    • backend timeouts defined in VGC can't use INFINITY (no math.h)
    • backend timeouts default to a negative value (the lack of zero override was also reported by @walid-git)
    • this is a VRT API breakage! (not the ABI)

I tried to be as thorough as possible, following the trail of relevant timeout parameters.

Fixes #3045

@dridi
Copy link
Member Author

dridi commented Mar 1, 2024

Of course I had to forget something, and it was Lck_CondWaitTimeout(), which I already added to the patch series. I decided to be prudent and keep support for zero meaning never timing out, but looking closely the only case where we use zero is actually in the Lck_CondWait() function, and Lck_CondWaitTimeout() when we forward a zero to Lck_CondWaitUntil().

So I think we could safely make zero no longer special, and in that case have a 1ms timed wait, or less.

@dridi dridi force-pushed the timeout_never branch 2 times, most recently from 9e3283f to 0a2f97d Compare March 4, 2024 17:15
dridi added 16 commits March 5, 2024 09:18
From now on, INFINITY disables the timeout and NAN is no longer allowed.

Refs varnishcache#3045
For all intents and purposes, it currently is exactly the same as the
timeout tweak. The duration parameters are either not really timeouts,
or timeouts that cannot be disabled. In other words, the timeout tweak
will grow the ability to formally disable a timeout.

Refs varnishcache#3045
The timeout type is the authority from which both the tweak and flag
are derived.
They were already relying on NAN to fall back to parameters.
We can't use NAN in VGC code today, so in order to convey the lack of
timeout setting in a backend definition, only a negative value makes
sense since zero will eventually mean zero instead of undefined.

This is an implicit breakage of the VRT ABI for the meaning of struct
vrt_backend.
Unlike session timeouts, they were not falling back to their parameter
counterparts from NAN. Since NAN is not allowed in VCL, they now behave
like session timeouts, returning their value or falling back to the
parameter when unset.
The vtim_real in Lck_CondWaitUntil() is not meant to be INFINITY, and it
should only apply to the vtim_dur passed to Lck_CondWaitTimeout(). In
practice it does since the latter calls the former. It could be enforced
by extracting a static function from Lck_CondWaitUntil().

This accommodates a few timeout parameters that are used for cond waits.
The timeout_* parameters are used in duration arithmetics and the
simplest is to not grant them the ability to be disabled.

Both timeout_idle and idle_send_timeout appear in a CondWait context.
For this reason both need to be capped to 1h, matching the implicit
limit in Lck_CondWaitTimeout().
@dridi dridi merged commit 460b9ce into varnishcache:master Mar 5, 2024
14 checks passed
@dridi dridi deleted the timeout_never branch March 5, 2024 08:52
walid-git added a commit to walid-git/varnish-cache that referenced this pull request Jul 15, 2024
walid-git added a commit to walid-git/varnish-cache that referenced this pull request Jul 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Setting backend timeouts to zero does not wait forever
1 participant