]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
commands: fix race when open()/close() cmd socket 2039/head
authorChristian Brauner <christian.brauner@ubuntu.com>
Thu, 14 Dec 2017 19:57:15 +0000 (20:57 +0100)
committerChristian Brauner <christian.brauner@ubuntu.com>
Thu, 14 Dec 2017 19:57:15 +0000 (20:57 +0100)
When we report STOPPED to a caller and then close the command socket it is
technically possible - and I've seen this happen on the test builders - that a
container start() right after a wait() will receive ECONNREFUSED because it
called open() before we close(). So 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.

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
src/lxc/start.c

index a144d6f8f791a59c2d8cbb1b85e3d303d971c7d8..4911fdde36833bb5eb1cdc0157666acaaf8fa53e 100644 (file)
@@ -753,12 +753,22 @@ void lxc_fini(const char *name, struct lxc_handler *handler)
 
        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)) {