Issue #1170 resolved

Bug in check_port running Python 3.3

Alex Hill
created an issue

The new exception hierarchy in Python 3.3 has created a bug in check_port in process/servers.py. IOError and socket.error are both now aliases of OSError, so a check for socket.error wrongly catches the IOError that's thrown in the try block.

This is fixed by throwing the IOError in an else block instead of in the try block. Starting on line 375 to the end of the function, change this:

{{{

!python

    try:
        s = socket.socket(af, socktype, proto)
        # See http://groups.google.com/group/cherrypy-users/
        #        browse_frm/thread/bbfe5eb39c904fe0
        s.settimeout(timeout)
        s.connect((host, port))
        s.close()
        raise IOError("Port %s is in use on %s; perhaps the previous "
                      "httpserver did not shut down properly." %
                      (repr(port), repr(host)))
    except socket.error:
        if s:
            s.close()

}}}

to this:

{{{

!python

    try:
        s = socket.socket(af, socktype, proto)
        # See http://groups.google.com/group/cherrypy-users/
        #        browse_frm/thread/bbfe5eb39c904fe0
        s.settimeout(timeout)
        s.connect((host, port))
        s.close()
    except socket.error:
        if s:
            s.close()
    else:
        raise IOError("Port %s is in use on %s; perhaps the previous "
                      "httpserver did not shut down properly." %
                      (repr(port), repr(host)))

}}}

Sorry this isn't a pull request, I don't have mercurial set up and bitbucket has no online editor.

Alex

Comments (2)

  1. Log in to comment