Issue #960 resolved

IOError Port 8080 not bound on '::0' in helloworld on IPv6

Jason R. Coombs
created an issue

I alter the cherrypy HelloWorld.py file with the following to enable the server on IPv6:

{{{ config = { 'global': {'server.socket_host':'::0'}, } cherrypy.quickstart(HelloWorld(), config=config) }}}

During startup, the following errors are reported: {{{ PS C:\Users\jaraco> .\helloworld.py [16/Sep/2009:14:17:26] ENGINE Listening for SIGTERM. [16/Sep/2009:14:17:26] ENGINE Bus STARTING [16/Sep/2009:14:17:26] ENGINE Set handler for console events. [16/Sep/2009:14:17:26] ENGINE Started monitor thread '_TimeoutMonitor'. [16/Sep/2009:14:17:26] ENGINE Started monitor thread 'Autoreloader'. [16/Sep/2009:14:17:31] ENGINE Error in 'start' listener <bound method Server.start of <cherrypy._cpserver.Server object at 0x00000000037699E8>> Traceback (most recent call last): File "C:\Python\lib\site-packages\cherrypy-3.2.0beta-py2.6.egg\cherrypy\process\wspbus.py", line 174, in publish output.append(listener(args, *kwargs)) File "C:\Python\lib\site-packages\cherrypy-3.2.0beta-py2.6.egg\cherrypy_cpserver.py", line 86, in start ServerAdapter.start(self) File "C:\Python\lib\site-packages\cherrypy-3.2.0beta-py2.6.egg\cherrypy\process\servers.py", line 62, in start self.wait() File "C:\Python\lib\site-packages\cherrypy-3.2.0beta-py2.6.egg\cherrypy\process\servers.py", line 103, in wait wait_for_occupied_port(host, port) File "C:\Python\lib\site-packages\cherrypy-3.2.0beta-py2.6.egg\cherrypy\process\servers.py", line 275, in wait_for_occ upied_port raise IOError("Port %r not bound on %r" % (port, host)) IOError: Port 8080 not bound on '::0'

[16/Sep/2009:14:17:31] ENGINE Shutting down due to error in start listener: Traceback (most recent call last): File "C:\Python\lib\site-packages\cherrypy-3.2.0beta-py2.6.egg\cherrypy\process\wspbus.py", line 211, in start self.publish('start') File "C:\Python\lib\site-packages\cherrypy-3.2.0beta-py2.6.egg\cherrypy\process\wspbus.py", line 191, in publish raise exc ChannelFailures: IOError("Port 8080 not bound on '::0'",) }}}

The application then responds on port 8080 on all IPv6 addresses. Trying to cancel the process with Ctrl-C or Ctrl-Break repeatedly fails with output similar to the following.

{{{ [16/Sep/2009:14:17:31] ENGINE Bus STOPPING [16/Sep/2009:14:17:31] ENGINE HTTP Server cherrypy._cpwsgi_server.CPWSGIServer(('::0', 8080)) already shut down [16/Sep/2009:14:17:31] ENGINE Stopped thread 'Autoreloader'. [16/Sep/2009:14:17:31] ENGINE Stopped thread '_TimeoutMonitor'. [16/Sep/2009:14:17:31] ENGINE Removed handler for console events. [16/Sep/2009:14:17:31] ENGINE Bus STOPPED [16/Sep/2009:14:17:31] ENGINE Bus EXITING [16/Sep/2009:14:17:31] ENGINE Bus EXITED Traceback (most recent call last): File "C:\Users\jaraco\projects\hrworx-util\python\formworx.openid\helloworld.py", line 12, in <module> cherrypy.quickstart(HelloWorld(), config=config) File "C:\Python\lib\site-packages\cherrypy-3.2.0beta-py2.6.egg\cherrypy__init__.py", line 247, in quickstart engine.start() File "C:\Python\lib\site-packages\cherrypy-3.2.0beta-py2.6.egg\cherrypy\process\wspbus.py", line 211, in start self.publish('start') File "C:\Python\lib\site-packages\cherrypy-3.2.0beta-py2.6.egg\cherrypy\process\wspbus.py", line 191, in publish raise exc cherrypy.process.wspbus.ChannelFailures: IOError("Port 8080 not bound on '::0'",) [16/Sep/2009:14:17:44] ENGINE Console event 0: shutting down bus [16/Sep/2009:14:17:44] ENGINE Handler for console events already off. [16/Sep/2009:14:17:44] ENGINE Bus STOPPING [16/Sep/2009:14:17:44] ENGINE HTTP Server cherrypy._cpwsgi_server.CPWSGIServer(('::0', 8080)) already shut down [16/Sep/2009:14:17:44] ENGINE No thread running for None. [16/Sep/2009:14:17:44] ENGINE No thread running for None. [16/Sep/2009:14:17:44] ENGINE Handler for console events already off. [16/Sep/2009:14:17:44] ENGINE Bus STOPPED [16/Sep/2009:14:17:44] ENGINE Bus EXITING [16/Sep/2009:14:17:44] ENGINE Bus EXITED }}}

I seem to recall this behavior was fixed in CherryPy 3.0, so this may be a regression. I'll follow up with more tests.

The output above is from a Windows Vista 64-bit machine on Python 2.6.2 (64-bit) running CherryPy 3.2beta (svn trunk r2530).

Comments (11)

  1. Robert Brewer

    OK, first, '::' works like a charm in Ubuntu 8.04, with Firefox pointed at `http://localhost:8088`. It also works fine when the app is served from Ubuntu, but browsed via Firefox in a Windows XP VM pointed at `http://my.ipv4.address:8088`.

    The patches I just committed in [2542] get us closer on Windows: the app no longer raises 'port not bound'. But I can't browse to it from FF, IE or Opera.

  2. Robert Brewer

    But I can't browse to it from FF, IE or Opera.

    ...which is understandable, since WinXP doesn't support dual-stack IPv6/4 sockets. Using `telnet ::1 8088` gets there just fine.

  3. Jason R. Coombs reporter

    The problem appears to be that '::0' is being passed to cherrypy.process.servers.wait_for_occupied_port, and check_port attempts to connect to ::0, which is not valid. When the user uses '0.0.0.0' as the bind address, the check address is translated to '127.0.0.1' for the purposes of wait_for_occupied_port. The same needs to be done for IPv6 (use '::1' to test the port).

  4. Jason R. Coombs reporter

    It turns out that the reason it is failing for me is because I'm using a non-canonical form for INADDR6_ANY. As in this bug description, I was using ::0 to bind to all addresses, but process/servers.py expects only :: at one point.

    I am attaching a new patch against the latest trunk. This patch addresses the issue, but because it also changes the logic somewhat, I want to run it by fumanchu. An alternate approach would be to simply add '::0' and '::0:0:0:0' to client_host().

    Probably the best solution would be to have something for parsing IPv6 addresses, such as the ipaddr project (http://code.google.com/p/ipaddr-py/). It's a single .py file, so probably could be included inline (still no dependencies).

  5. Log in to comment