Fixing openssh to avoid occasional spurious connection failures

Jonathan Kamens jik@curl.com
Wed Nov 7 06:42:00 GMT 2001


As I just noted in
<URL:http://www.cygwin.com/ml/cygwin-developers/2001-11/msg00080.html>,
ssh connections from Cygwin can occasionally fail because a winsock
bug causes the connection to be assigned a local port number which is
already in use.

The simplest workaround for this problem would be to put a default
"ConnectionAttempts 4" setting in the ssh_config that gets generated
by ssh-host-config.

The next simplest workaround would be to get the OpenSSH maintainers
to apply this patch:

  Index: readconf.c
  ===================================================================
  RCS file: /cvs/openssh_cvs/readconf.c,v
  retrieving revision 1.66
  diff -u -r1.66 readconf.c
  --- readconf.c	2001/10/03 17:39:39	1.66
  +++ readconf.c	2001/11/15 21:27:55
  @@ -870,7 +870,11 @@
          if (options->port == -1)
                  options->port = 0;	/* Filled in ssh_connect. */
          if (options->connection_attempts == -1)
  +#ifdef HAVE_CYGWIN
  +		options->connection_attempts = 4;
  +#else
                  options->connection_attempts = 1;
  +#endif
          if (options->number_of_password_prompts == -1)
                  options->number_of_password_prompts = 3;
          /* Selected in ssh_login(). */

The advantage of this fix is that it will work for people who already
have an ssh_config file.

The disadvantage of either of the two fixes given above is that
although the connection will succeed, it'll also print out warnings of
the form "ssh: connect to address XXX.XXX.XXX.XXX port 22: Address
already in use" before it succeeds.  Something like this could be used
to fix that:

  Index: sshconnect.c
  ===================================================================
  RCS file: /cvs/openssh_cvs/sshconnect.c,v
  retrieving revision 1.80
  diff -u -r1.80 sshconnect.c
  --- sshconnect.c	2001/10/10 05:07:45	1.80
  +++ sshconnect.c	2001/11/15 21:39:02
  @@ -330,6 +330,10 @@
                          } else {
                                  if (errno == ECONNREFUSED)
                                          full_failure = 0;
  +#ifdef HAVE_CYGWIN
  +                                if ((errno != EADDRINUSE) ||
  +                                    (attempt == connection_attempts - 1))
  +#endif
                                  log("ssh: connect to address %s port %s: %s",
                                      sockaddr_ntop(ai->ai_addr), strport,
                                      strerror(errno));

Jonathan Kamens



More information about the Cygwin-apps mailing list