From: Serge Hallyn Date: Thu, 14 Dec 2017 21:56:24 +0000 (-0600) Subject: Merge pull request #2039 from brauner/2017-12-14/fix_command_socket_race X-Git-Tag: lxc-3.0.0.beta1~107 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=389c46753ba4a8bf446575cc6e2ab508309bd9b2;p=thirdparty%2Flxc.git Merge pull request #2039 from brauner/2017-12-14/fix_command_socket_race commands: fix race when open()/close() cmd socket --- 389c46753ba4a8bf446575cc6e2ab508309bd9b2 diff --cc src/lxc/start.c index 5052e2d5a,4911fdde3..e17507606 --- a/src/lxc/start.c +++ b/src/lxc/start.c @@@ -784,15 -753,25 +784,25 @@@ void lxc_fini(const char *name, struct cgroup_destroy(handler); - lxc_set_state(name, handler, STOPPED); + /* This function will try to connect to the legacy lxc-monitord state + * server and only exists for backwards compatibility. + */ + lxc_monitor_send_state(name, STOPPED, handler->lxcpath); if (handler->conf->reboot == 0) { - /* close command socket */ + /* For all new state clients simply close the command socket. + * This will inform all state clients that the container is + * STOPPED and also prevents a race between a open()/close() on + * the command socket causing a new process to get ECONNREFUSED + * because we haven't yet closed the command socket. + */ close(handler->conf->maincmd_fd); handler->conf->maincmd_fd = -1; + } else { + lxc_set_state(name, handler, STOPPED); } - if (run_lxc_hooks(name, "post-stop", handler->conf, handler->lxcpath, NULL)) { + if (run_lxc_hooks(name, "post-stop", handler->conf, NULL)) { ERROR("Failed to run lxc.hook.post-stop for container \"%s\".", name); if (handler->conf->reboot) { WARN("Container will be stopped instead of rebooted.");