This is the mail archive of the mailing list for the Cygwin project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Fixing openssh to avoid occasional spurious connection failures

As I just noted in
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;
                  options->connection_attempts = 1;
          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))
                                  log("ssh: connect to address %s port %s: %s",
                                      sockaddr_ntop(ai->ai_addr), strport,

Jonathan Kamens

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]