SetPushDispatchConfig overrides the timings; zero keeps the current value. Server startup calls it from the PAD_PUSH_DISPATCH_* knobs (cmd/pad configurePush, TASK-3939 part C) and passes 0 for sendTimeout, which has no knob because notify.SendTimeout is baked into the gateway's HTTP client. interval
(interval, settle, lease, leaseMargin, sendTimeout time.Duration)
| 135 | // changes; the error wraps errPushLeaseTooShort and states the RESOLVED lease, |
| 136 | // send timeout and margin, so a caller can tell which knob caused it. |
| 137 | func (s *Server) SetPushDispatchConfig(interval, settle, lease, leaseMargin, sendTimeout time.Duration) error { |
| 138 | cur := s.resolvePushDispatchSettings() |
| 139 | pick := func(v, d time.Duration) time.Duration { |
| 140 | if v > 0 { |
| 141 | return v |
| 142 | } |
| 143 | return d |
| 144 | } |
| 145 | next := pushDispatchSettings{ |
| 146 | interval: pick(interval, cur.interval), settle: pick(settle, cur.settle), |
| 147 | lease: pick(lease, cur.lease), leaseMargin: pick(leaseMargin, cur.leaseMargin), |
| 148 | sendTimeout: pick(sendTimeout, cur.sendTimeout), |
| 149 | } |
| 150 | // sendTimeout + leaseMargin wraps negative when the margin is within |
| 151 | // sendTimeout of MaxInt64 (ParseDuration accepts up to about 2562047h), and |
| 152 | // the wrapped sum would pass the comparison below. Such a margin exceeds |
| 153 | // every representable lease, so it is the same violation (TASK-3939 part C, |
| 154 | // decision 37e3eafa). Every other use of these durations is time.Time.Add or |
| 155 | // NewTicker, which cannot wrap at this magnitude, so no cap is needed. |
| 156 | if next.leaseMargin > math.MaxInt64-next.sendTimeout || next.lease < next.sendTimeout+next.leaseMargin { |
| 157 | slog.Warn("push dispatch: config refused", "reason", "lease shorter than send timeout plus margin") |
| 158 | return fmt.Errorf("%w: lease %s is shorter than send timeout %s plus margin %s", errPushLeaseTooShort, next.lease, next.sendTimeout, next.leaseMargin) |
| 159 | } |
| 160 | d := &s.pushDispatch |
| 161 | d.mu.Lock() |
| 162 | defer d.mu.Unlock() |
| 163 | d.interval, d.settle, d.lease, d.leaseMargin, d.sendTimeout = next.interval, next.settle, next.lease, next.leaseMargin, next.sendTimeout |
| 164 | return nil |
| 165 | } |
| 166 | |
| 167 | // SetPushSender substitutes the gateway client (a test seam). |
| 168 | func (s *Server) SetPushSender(p pushSender) { |