Applying the "Connection reset by peer"
Max Bowsher
maxb at ukf.net
Thu Aug 22 09:01:02 EST 2002
bart.coninckx at watco.be wrote:
> Hi all,
>
> we're suffering heavily from the "connection reset by peer" problem
> when running Rsync on WinNT.
> Great was our relief when seeing Randy's message in
> http://www.mail-archive.com/rsync@lists.samba.org/msg01918.html
>
> I immediately installed the full Cygwin to recompile Rsync, but since
> I'm far from a C guru, I'm a bit puzzled with the last 2 lines in
> Randy's patch:
>
> cleanup.c:_exit_cleanup() just before exit(code)
> socket.c:start_accept_loop() just before _exit(ret)
>
>
> should I simply put "_exit_cleanup()" before "exit(code)" in
> cleanup.c with nothing in between the "()" ? (same for socket.c?)
Not quite - put "close_all();" there. But the socket.c code seems to have
changed since then. The temporary variable ret seems to have been tidied away.
I have attached a patch against rsync-2.5.5:
cd rsync-2.5.5 # wherever you unpacked the source tarball
patch -i crbp.patch
It adds the temporary variable I mention above, and implements the instructions
given in the email link you mention above.
Please note, that I have simply made the instructions easier to follow, I have
not checked them for correctness. (Although I don't see anything obviously
wrong.)
> I disregard these two lines and compiled the EXE again and it seems
> to be working, haven't tested it thoroughly though...
Without adding those 2 calls to close_all(), there should be no change.
Max.
-------------- next part --------------
--- socket.c.orig 2002-08-22 18:43:18.000000000 +0100
+++ socket.c 2002-08-22 18:48:11.000000000 +0100
@@ -427,11 +427,14 @@
#endif
if ((pid = fork()) == 0) {
+ int ret;
close(s);
/* open log file in child before possibly giving
up privileges */
log_open();
- _exit(fn(fd));
+ ret = fn(fd);
+ close_all();
+ _exit(ret);
} else if (pid < 0) {
rprintf(FERROR,
RSYNC_NAME
--- cleanup.c.orig 2002-08-22 18:43:13.000000000 +0100
+++ cleanup.c 2002-08-22 18:45:15.000000000 +0100
@@ -35,6 +35,32 @@
pid_t cleanup_child_pid = -1;
+void close_all()
+/* rmo: 5/31/01
+ Close all open sockets and files, allowing a (somewhat) graceful
+ shutdown() of socket connections. This eliminates the abortive
+ TCP RST sent by a Winsock-based system when the close() occurs.
+
+ See http://www.mail-archive.com/rsync@lists.samba.org/msg01918.html
+*/
+{
+ int max_fd;
+ int fd;
+ int ret;
+ struct stat st;
+
+ max_fd = sysconf(_SC_OPEN_MAX) - 1;
+ for (fd = max_fd; fd >= 0; fd--) {
+ ret = fstat(fd,&st);
+ if (fstat(fd,&st) == 0){ /* Open fd */
+ if (is_a_socket(fd)) {
+ ret = shutdown(fd,2); /* Somewhat graceful */
+ }
+ ret = close(fd);
+ }
+ }
+}
+
/*
* Code is one of the RERR_* codes from errcode.h.
*/
@@ -90,6 +116,7 @@
rprintf(FINFO,"_exit_cleanup(code=%d, file=%s, line=%d): about to call exit(%d)\n",
ocode, file, line, code);
+ close_all();
exit(code);
}
More information about the rsync
mailing list