Browse Source

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>
travis-debug
Rusty Russell 5 years ago
committed by neil saitug
parent
commit
2b7e5f7f5a
  1. 11
      common/dev_disconnect.c

11
common/dev_disconnect.c

@ -4,6 +4,8 @@
#include <common/dev_disconnect.h>
#include <common/status.h>
#include <fcntl.h>
#include <netinet/in.h>
#include <netinet/tcp.h>
#include <stdlib.h>
#include <sys/socket.h>
#include <sys/stat.h>
@ -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]);

Loading…
Cancel
Save