]> git.kaiwu.me - nginx.git/commitdiff
Resolver: make TCP write timer event cancelable.
authorAleksei Bavshin <a.bavshin@f5.com>
Thu, 2 Jun 2022 03:17:23 +0000 (20:17 -0700)
committerAleksei Bavshin <a.bavshin@f5.com>
Thu, 2 Jun 2022 03:17:23 +0000 (20:17 -0700)
Similar to 70e65bf8dfd7, the change is made to ensure that the ability to
cancel resolver tasks is fully controlled by the caller.  As mentioned in the
referenced commit, it is safe to make this timer cancelable because resolve
tasks can have their own timeouts that are not cancelable.

The scenario where this may become a problem is a periodic background resolve
task (not tied to a specific request or a client connection), which receives a
response with short TTL, large enough to warrant fallback to a TCP query.
With each event loop wakeup, we either have a previously set write timer
instance or schedule a new one.  The non-cancelable write timer can delay or
block graceful shutdown of a worker even if the ngx_resolver_ctx_t->cancelable
flag is set by the API user, and there are no other tasks or connections.

We use the resolver API in this way to maintain the list of upstream server
addresses specified with the 'resolve' parameter, and there could be third-party
modules implementing similar logic.

src/core/ngx_resolver.c

index 6d129e56aff9bbe64f34125d6045f8c0ec6d485f..b3947f5fd1691d8532e89075fda578db6c4ba62e 100644 (file)
@@ -1389,6 +1389,7 @@ ngx_resolver_send_tcp_query(ngx_resolver_t *r, ngx_resolver_connection_t *rec,
 
         rec->tcp->data = rec;
         rec->tcp->write->handler = ngx_resolver_tcp_write;
+        rec->tcp->write->cancelable = 1;
         rec->tcp->read->handler = ngx_resolver_tcp_read;
         rec->tcp->read->resolver = 1;