Bug 1752 - Test port not available during make tests
Summary: Test port not available during make tests
Status: CLOSED WONTFIX
Alias: None
Product: Portable OpenSSH
Classification: Unclassified
Component: Regression tests (show other bugs)
Version: 5.4p1
Hardware: All All
: P2 normal
Assignee: Assigned to nobody
URL:
Keywords:
Depends on:
Blocks: V_5_6
  Show dependency treegraph
 
Reported: 2010-04-10 03:39 AEST by petesea
Modified: 2010-08-27 10:28 AEST (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description petesea 2010-04-10 03:39:02 AEST
While building the latest OpenSSH from CVS (2010-04-09), "make tests" fails with the error "no sshd running on port 4242".  The real cause in my case is that something is already running on port 4242 (the Juniper Network Connect client).

It would be nice if the error message were a bit more helpful, eg:

   no sshd running on port 4242, try setting $TEST_SSH_PORT to a different port

To go a step further, it might be nice if the code used to set the port was a bit more resilient, with an error message more informative.

Maybe the code in test-exec.sh:

  if [ ! -z "$TEST_SSH_PORT" ]; then
    PORT="$TEST_SSH_PORT"
  else
    PORT=4242
  fi

could be something similar to:

  if [ ! -z "$TEST_SSH_PORT" ]; then
    PORT="$TEST_SSH_PORT"
  else
    first_port=4200
    last_port=4300

    test_port=$first_port
    while [ "$test_port" -le "$last_port" ]; do
      netstat -na | grep "[:.]$test_port " >/dev/null 2>&1 || { PORT=$test_port; break; }
      test_port=`expr $test_port + 1`
    done

    if [ -z "$PORT" ]; then
      echo "Unable to find usable test port between $first_port and $last_port.  Define \$TEST_SSH_PORT."
      exit 2
    fi
  fi

I realize the 'netstat | grep' command above may not be the best, most portable way to look for an available port, but the idea is the same... ie. run something that checks to see if the requested port is available or not.  FYI, I did run the above code on several boxes (solaris, hpux, macosx, fedora, redhat, centos, cygwin) and it seemed to work fine.

Another possible way to check would be to run sshd -D and look at the output.  In my case it says:

  Bind to port 4242 on 127.0.0.1 failed: Address already in use.
  Cannot bind any address.

Which (again in my particular case), would have been a much more helpful error message then "no sshd running on port 4242".

Unfortunately, with this approach the sshd command would need to be killed/terminated somehow.

Or... maybe the sshd -t (or -T) option could be enhanced (or a new option created) that checks to see if the port is available, but doesn't actually start a server.  I suspect this really means it would try to bind to that port and then just close if it works, otherwise report the error. Problem is, on some systems I believe it can take a while before a port can be reused... so a passive check may be better.
Comment 1 Darren Tucker 2010-04-23 10:50:28 AEST
The sshd port isn't the only port this can happen to, it can also happen during the port forwarding tests which use different ports.  It might be worth adding the test you suggest (doing it portably is hard though).

I agree that the error reporting from the tests is not very good, and that debugging tests is tricky.  I attempted to add a wrapper to catch the debug output on stderr but that was not very successful.
Comment 2 Damien Miller 2010-08-10 04:25:14 AEST
I think any attempts to check for an open port using netstat or similar are doomed to fail because of cross-platform incompatibilities. Users of the test scripts should just arrange for the port to be free on the systems they test under or edit test-exec.sh to pick a new, free port there.
Comment 3 petesea 2010-08-10 04:38:34 AEST
(In reply to comment #2)
> I think any attempts to check for an open port using netstat or similar
> are doomed to fail because of cross-platform incompatibilities. Users
> of the test scripts should just arrange for the port to be free on the
> systems they test under or edit test-exec.sh to pick a new, free port
> there.

Understood.   How about just making the error message a bit more clear?

eg:

  no sshd running on port 4242, try setting $TEST_SSH_PORT to a
  different port

That way, at least users who encounter this problem don't need to go digging around to figure out the solution is to set $TEST_SSH_PORT.
Comment 4 Darren Tucker 2010-08-27 10:28:05 AEST
With the release of OpenSSH 5.6p1 this bug is now considered closed.  If you have further problems please reopen or file a new bug as appropriate.