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 <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell 2019-10-08 11:34:24 +10:30 committed by neil saitug
parent 6e7cfcc76e
commit 2b7e5f7f5a

View File

@ -4,6 +4,8 @@
#include <common/dev_disconnect.h> #include <common/dev_disconnect.h>
#include <common/status.h> #include <common/status.h>
#include <fcntl.h> #include <fcntl.h>
#include <netinet/in.h>
#include <netinet/tcp.h>
#include <stdlib.h> #include <stdlib.h>
#include <sys/socket.h> #include <sys/socket.h>
#include <sys/stat.h> #include <sys/stat.h>
@ -96,6 +98,15 @@ void dev_sabotage_fd(int fd)
/* Close one. */ /* Close one. */
close(fds[0]); 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. */ /* Move other over to the fd we want to sabotage. */
dup2(fds[1], fd); dup2(fds[1], fd);
close(fds[1]); close(fds[1]);