Max Bowsher
2002-Apr-03 20:39 UTC
Patch to avoid 'Connection reset by peer' error for rsync on cygwin
The problem is caused because rsync does not close its sockets, and WinSock is a quite strict on this. The solution is to shutdown and close the fd. This is a 5-minute hack I've done to fix the obvious occurrences of the problem. It might be better to extend rsyncs cleanup functions for this, but here it is anyway to alert people to the problem and its fix. Max. BEGIN PATCH diff -mru rsync-2.5.5/clientserver.c rsync-2.5.5-tweaked/clientserver.c --- rsync-2.5.5/clientserver.c Wed Mar 27 01:03:13 2002 +++ rsync-2.5.5-tweaked/clientserver.c Wed Apr 3 11:01:57 2002 @@ -486,39 +486,44 @@ } if (!read_line(fd, line, sizeof(line)-1)) { - return -1; + goto exitwithnomodule; } if (sscanf(line,"@RSYNCD: %d", &remote_version) != 1) { io_printf(fd,"@ERROR: protocol startup error\n"); - return -1; + goto exitwithnomodule; } while (i == -1) { line[0] = 0; if (!read_line(fd, line, sizeof(line)-1)) { - return -1; + goto exitwithnomodule; } if (!*line || strcmp(line,"#list")==0) { send_listing(fd); - return -1; + goto exitwithnomodule; } if (*line == '#') { /* it's some sort of command that I don't understand */ io_printf(fd,"@ERROR: Unknown command '%s'\n", line); - return -1; + goto exitwithnomodule; } i = lp_number(line); if (i == -1) { io_printf(fd,"@ERROR: Unknown module '%s'\n", line); - return -1; + goto exitwithnomodule; } } return rsync_module(fd, i); + +exitwithnomodule: + shutdown(fd,SHUT_WR); + close(fd); + return -1; } END PATCH
Dave Dykstra
2002-Apr-25 14:55 UTC
Patch to avoid 'Connection reset by peer' error for rsync on cygwin
Does anybody know if this might cause problems on non-Windows machines? Would "shutdown" need to be checked in configure, or is it implemented on all Unix variants? I don't recall ever seeing a need for it on Unix. - Dave On Wed, Apr 03, 2002 at 11:39:57AM +0100, Max Bowsher wrote:> The problem is caused because rsync does not close its sockets, and WinSock is a > quite strict on this. The solution is to shutdown and close the fd. > This is a 5-minute hack I've done to fix the obvious occurrences of the problem. > It might be better to extend rsyncs cleanup functions for this, but here it is > anyway to alert people to the problem and its fix. > > Max. > > BEGIN PATCH > diff -mru rsync-2.5.5/clientserver.c rsync-2.5.5-tweaked/clientserver.c > --- rsync-2.5.5/clientserver.c Wed Mar 27 01:03:13 2002 > +++ rsync-2.5.5-tweaked/clientserver.c Wed Apr 3 11:01:57 2002 > @@ -486,39 +486,44 @@ > } > > if (!read_line(fd, line, sizeof(line)-1)) { > - return -1; > + goto exitwithnomodule; > } > > if (sscanf(line,"@RSYNCD: %d", &remote_version) != 1) { > io_printf(fd,"@ERROR: protocol startup error\n"); > - return -1; > + goto exitwithnomodule; > } > > while (i == -1) { > line[0] = 0; > if (!read_line(fd, line, sizeof(line)-1)) { > - return -1; > + goto exitwithnomodule; > } > > if (!*line || strcmp(line,"#list")==0) { > send_listing(fd); > - return -1; > + goto exitwithnomodule; > } > > if (*line == '#') { > /* it's some sort of command that I don't understand */ > io_printf(fd,"@ERROR: Unknown command '%s'\n", line); > - return -1; > + goto exitwithnomodule; > } > > i = lp_number(line); > if (i == -1) { > io_printf(fd,"@ERROR: Unknown module '%s'\n", line); > - return -1; > + goto exitwithnomodule; > } > } > > return rsync_module(fd, i); > + > +exitwithnomodule: > + shutdown(fd,SHUT_WR); > + close(fd); > + return -1; > } > > > END PATCH > > > > > -- > To unsubscribe or change options: http://lists.samba.org/mailman/listinfo/rsync > Before posting, read: http://www.tuxedo.org/~esr/faqs/smart-questions.html
David Bolen
2002-Apr-26 10:21 UTC
Patch to avoid 'Connection reset by peer' error for rsync on cygwin
Max Bowsher [maxb@ukf.net] writes:> I though that shutdown acts as below:(no data loss)> SUSv2 is annoyingly somewhat vague on the specifics.So are the FreeBSD/Linux man pages. They don't specifically indicate truncation or flushing of data, although I don't recall ever thinking of shutdown() as truncating. To be, what Microsoft got wrong in WinSock is _requiring_ shutdown() to reliably close a socket while ensuring all final data gets delivered. It certainly caught me by surprise (and annoyance) at one point. I rarely ever used it in a Unix environment, but I do think it should be safe. -- David /-----------------------------------------------------------------------\ \ David Bolen \ E-mail: db3l@fitlinxx.com / | FitLinxx, Inc. \ Phone: (203) 708-5192 | / 860 Canal Street, Stamford, CT 06902 \ Fax: (203) 316-5150 \ \-----------------------------------------------------------------------/
Max Bowsher
2002-Apr-29 07:04 UTC
Patch to avoid 'Connection reset by peer' error for rsync on cygwin
What is the status of this patch? (Ideally I'd like it to make it in to 2.5.6, so I can stop using a modified version). I have successfully used rsync with the patch on Linux, and have done a test where a client does connect(), then sleep(), whilst the server does write(), shutdown(,SHUT_WR),close(), before the client does read(), and this completes successfully. If there is anything else I should do to help it along, please let me know. Max.
Seemingly Similar Threads
- [PATCH] (Resubmission) 'Connection reset by peer' with rsync server on cygwin
- patch for linux capabilities
- rsync server over SSH [includes code patches]
- rsync error using ssh : @ERROR: access denied to server.domain.com from unknown (0.0.0.0) {Scanned By MailScanner}
- rsyncd + scripting