prebid-server icon indicating copy to clipboard operation
prebid-server copied to clipboard

Improve the timeout mechanism in the hook executor

Open scr-oath opened this issue 1 year ago • 1 comments

Current code in the hook executor seems to implement a timeout using the time.Timer rather than context.WithTimeout. The shortcoming of this, is that any outgoing requests or other activity is blind to whether the goroutine should continue to run. If a timeout occurs, the hook still continues running indefinitely.

The proposal would be to:

  1. Use context.WithTimeout and defer cancel()
  2. select either the response channel or the <-ctx.Done()
  3. Ensure the error is reported regardless of success or failure (as, I believe it already is)

This would ensure that any work being done in a module hook and, especially, outgoing http requests, would be aware of this timeout and stop working as soon as possible, rather than continuing indefinitely when its response will be ignored.

scr-oath avatar Oct 09 '24 15:10 scr-oath

This is related to #3962. We'll need to first pass the auction context to the module infrastructure.

It would also be beneficial to add additional metrics that allow us to visualize how often different types of auction errors like context timeout, deadline exceeded, etc are occurring which might require further discussion. @bsardo to open another ticket for this so we can nail down the requirements.

bsardo avatar Nov 01 '24 14:11 bsardo