| 
									
										
										
										
											2019-03-29 19:40:23 +00:00
										 |  |  | # cancel
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ## Name
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-09-08 00:26:16 -07:00
										 |  |  | *cancel* - cancels a request's context after 5001 milliseconds. | 
					
						
							| 
									
										
										
										
											2019-03-29 19:40:23 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | ## Description
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | The *cancel* plugin creates a canceling context for each request. It adds a timeout that gets | 
					
						
							|  |  |  | triggered after 5001 milliseconds. | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-09-08 00:26:16 -07:00
										 |  |  | The 5001 number was chosen because the default timeout for DNS clients is 5 seconds, after that they | 
					
						
							| 
									
										
										
										
											2019-03-29 19:40:23 +00:00
										 |  |  | 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. | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-01-31 12:37:24 +01:00
										 |  |  | ## Syntax
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-29 19:40:23 +00:00
										 |  |  | ~~~ txt | 
					
						
							|  |  |  | cancel [TIMEOUT] | 
					
						
							|  |  |  | ~~~ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | * **TIMEOUT** allows setting a custom timeout. The default timeout is 5001 milliseconds (`5001 ms`) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ## Examples
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ~~~ corefile | 
					
						
							| 
									
										
										
										
											2019-09-19 14:17:53 +01:00
										 |  |  | example.org { | 
					
						
							| 
									
										
										
										
											2019-03-29 19:40:23 +00:00
										 |  |  |     cancel | 
					
						
							|  |  |  |     whoami | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | ~~~ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | Or with a custom timeout: | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ~~~ corefile | 
					
						
							| 
									
										
										
										
											2019-09-19 14:17:53 +01:00
										 |  |  | example.org { | 
					
						
							| 
									
										
										
										
											2019-03-29 19:40:23 +00:00
										 |  |  |     cancel 1s | 
					
						
							|  |  |  |     whoami | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | ~~~ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-28 18:56:35 +01:00
										 |  |  | ## See Also
 | 
					
						
							| 
									
										
										
										
											2019-03-29 19:40:23 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | The Go documentation for the context package. |