From 2b7e5f7f5a58599c737f89c50e2cecee679ea62d Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Tue, 8 Oct 2019 11:34:24 +1030 Subject: [PATCH] dev_disconnect: make it more reliable. I have seen some strange flakiness (under VALGRIND), which I have traced down to dev-disconnect "+" not working as expected. In particular, the message is not sent out before closing the fd. This seems to fix it on Linux, though it's so intermittant that it's hard to be completely sure. Signed-off-by: Rusty Russell --- common/dev_disconnect.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/common/dev_disconnect.c b/common/dev_disconnect.c index 0b380e141..8a3b98a19 100644 --- a/common/dev_disconnect.c +++ b/common/dev_disconnect.c @@ -4,6 +4,8 @@ #include #include #include +#include +#include #include #include #include @@ -96,6 +98,15 @@ void dev_sabotage_fd(int fd) /* Close one. */ close(fds[0]); + +#if defined(TCP_NODELAY) + /* On Linux, at least, this flushes. */ + int opt = TCP_NODELAY; + int val = 1; + setsockopt(fd, IPPROTO_TCP, opt, &val, sizeof(val)); +#else +#error No TCP_NODELAY? +#endif /* Move other over to the fd we want to sabotage. */ dup2(fds[1], fd); close(fds[1]);