Commit aa631423 authored by Evan Hunt's avatar Evan Hunt
Browse files

purge pending command events when cancelled

When the readmessage callback is called with ISC_R_CANCELED,
that means the network manager is shutting down. There may be
command tasks that have been scheduled or are currently running,
and there will be no point to trying to run them or send a response
after they complete, so we purge all outstanding tasks and mark
the control channel as shutting down.

(Note that there is still a tiny window for a race if the shutdown
should occur on the tick between checking whether the control channel
is shutting down and sending a response in control_respond(). We may
want to address this by putting a mutex around controls->shuttingdown.)
parent 2db8acc3
......@@ -324,13 +324,18 @@ control_respond(isc_nmhandle_t *handle, isc_result_t result, void *arg) {
r.base = conn->buffer->base;
r.length = conn->buffer->used;
isc_nmhandle_ref(handle);
conn->sending = true;
result = isc_nm_send(handle, &r, control_senddone, conn);
if (result != ISC_R_SUCCESS) {
isc_nmhandle_unref(handle);
conn->sending = false;
goto cleanup;
/*
* Make sure the control channel hasn't been shut down
* in the meantime.
*/
if (!listener->controls->shuttingdown) {
isc_nmhandle_ref(handle);
conn->sending = true;
result = isc_nm_send(handle, &r, control_senddone, conn);
if (result != ISC_R_SUCCESS) {
isc_nmhandle_unref(handle);
conn->sending = false;
}
}
cleanup:
......@@ -382,7 +387,14 @@ control_recvmessage(isc_nmhandle_t *handle, isc_result_t result, void *arg) {
}
if (result != ISC_R_SUCCESS) {
if (result != ISC_R_CANCELED && result != ISC_R_EOF) {
if (result == ISC_R_CANCELED) {
/*
* Don't bother with any more scheduled command events.
*/
listener->controls->shuttingdown = true;
isc_task_purge(named_g_server->task, NULL,
NAMED_EVENT_COMMAND, NULL);
} else if (result != ISC_R_EOF) {
log_invalid(&conn->ccmsg, result);
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment