]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
varlink: add server write states to disconnect check
authorAnita Zhang <the.anitazha@gmail.com>
Wed, 9 Sep 2020 01:35:27 +0000 (18:35 -0700)
committerAnita Zhang <the.anitazha@gmail.com>
Wed, 7 Oct 2020 23:17:23 +0000 (16:17 -0700)
While a server is in the VARLINK_PENDING_METHOD or VARLINK_PENDING_METHOD_MORE
states and its write end is disconnected and it gets a POLLHUP, we
should disconnect since it can't write anymore.

In the case of systemd-oomd disconnecting while pid1 was pending-more, this
condition left pid1 in a state where it started throttling from
continually getting POLLHUP.

src/shared/varlink.c

index 86b5f08ae76dcd7f2f3e4a9d38c76ace2bbc706d..fabfe78280b5e44212aecf6a7311e7578d1b0e04 100644 (file)
@@ -418,6 +418,11 @@ static int varlink_test_disconnect(Varlink *v) {
         if (IN_SET(v->state, VARLINK_IDLE_CLIENT) && (v->write_disconnected || v->got_pollhup))
                 goto disconnect;
 
+        /* The server is still expecting to write more, but its write end is disconnected and it got a POLLHUP
+         * (i.e. from a disconnected client), so disconnect. */
+        if (IN_SET(v->state, VARLINK_PENDING_METHOD, VARLINK_PENDING_METHOD_MORE) && v->write_disconnected && v->got_pollhup)
+                goto disconnect;
+
         return 0;
 
 disconnect: