mirror of
https://github.com/coredns/coredns.git
synced 2025-12-07 19:05:19 -05:00
plugin/cancel: add context cancelation plugin (#2711)
* plugin/cancel: add context cancelation plugin Per review comments on #2704, move this into a plugin that gets called. Add the most minimal plugin, tests and documenation. Signed-off-by: Miek Gieben <miek@miek.nl> * plugin/cache: add timeout option review feedback: add option to set custom timeout. Signed-off-by: Miek Gieben <miek@miek.nl> * spelling Signed-off-by: Miek Gieben <miek@miek.nl>
This commit is contained in:
45
plugin/cancel/README.md
Normal file
45
plugin/cancel/README.md
Normal file
@@ -0,0 +1,45 @@
|
||||
# cancel
|
||||
|
||||
## Name
|
||||
|
||||
*cancel* - a plugin that cancels a request's context after 5001 milliseconds.
|
||||
|
||||
## Description
|
||||
|
||||
The *cancel* plugin creates a canceling context for each request. It adds a timeout that gets
|
||||
triggered after 5001 milliseconds.
|
||||
|
||||
The 5001 number is chosen because the default timeout for DNS clients is 5 seconds, after that they
|
||||
give up.
|
||||
|
||||
A plugin interested in the cancellation status should call `plugin.Done()` on the context. If the
|
||||
context was canceled due to a timeout the plugin should not write anything back to the client and
|
||||
return a value indicating CoreDNS should not either; a zero return value should suffice for that.
|
||||
|
||||
~~~ txt
|
||||
cancel [TIMEOUT]
|
||||
~~~
|
||||
|
||||
* **TIMEOUT** allows setting a custom timeout. The default timeout is 5001 milliseconds (`5001 ms`)
|
||||
|
||||
## Examples
|
||||
|
||||
~~~ corefile
|
||||
. {
|
||||
cancel
|
||||
whoami
|
||||
}
|
||||
~~~
|
||||
|
||||
Or with a custom timeout:
|
||||
|
||||
~~~ corefile
|
||||
. {
|
||||
cancel 1s
|
||||
whoami
|
||||
}
|
||||
~~~
|
||||
|
||||
## Also See
|
||||
|
||||
The Go documentation for the context package.
|
||||
Reference in New Issue
Block a user