Download Install Tutorial Docs FAQ Tools WikiLicense Team IRC Planet Involvement Shop Book

Ticket #645 (enhancement)

Opened 2 years ago

Last modified 10 months ago

A value of 0 for socket_port should cause CP to bind to an avaibale unused port

Status: assigned

Reported by: draghuram@gmail.com Assigned to: fumanchu (accepted)
Priority: normal Milestone: 3.2
Component: wsgiserver Keywords:
Cc:

When socket_port is specified as 0, an exception is thrown as follows:

File
"/localhome/raghu/localwork/cherrypy/svn.cherrypy.org/trunk/cherrypy/_cpserver.py",
line 69, in quickstart
    self.start()
  File
"/localhome/raghu/localwork/cherrypy/svn.cherrypy.org/trunk/cherrypy/_cpserver.py",
line 95, in start
    self._start_http(httpserver)
  File
"/localhome/raghu/localwork/cherrypy/svn.cherrypy.org/trunk/cherrypy/_cpserver.py",
line 118, in _start_http
    self.wait(httpserver)
  File
"/localhome/raghu/localwork/cherrypy/svn.cherrypy.org/trunk/cherrypy/_cpserver.py",
line 159, in wait
    wait_for_occupied_port(*bind_addr)
  File
"/localhome/raghu/localwork/cherrypy/svn.cherrypy.org/trunk/cherrypy/_cpserver.py",
line 247, in wait_for_occupied_port
    raise IOError(msg)
IOError: Port 0 not bound on 'localhost'

I am using the latest code from the trunk. It appears to me that even though wsgiserver is properly passing 0 to socket.bind (and hence binding to an unused port), other parts of the code still use "configured" port which is 0.

Attachments

port0.diff (1.6 kB) - added by guest on 01/25/07 14:27:31.

Change History

01/25/07 14:27:31: Modified by guest

  • attachment port0.diff added.

01/25/07 14:28:05: Modified by draghuram@gmail.com

I am attaching a small patch that seems to work with port 0. My only intention in uploading the patch is to suggest it as a starting point. It will take more time for me to understand all its implications and suggest a more thorough solution.

The web server will update its bind_addr after doing socket.bind() so that correct port can be obtained. This port will obviously be different from the original port if the original port was 0. Unfortunately, the code that started the web server needs to wait for this setting before proceeding further. Right now, I just added time.sleep(5) as I don't know of a better solution.

01/26/07 00:12:43: Modified by fumanchu

  • owner changed from rdelon to fumanchu.
  • status changed from new to assigned.
  • milestone set to 3.0.

That's a good start, but there's no API guarantee that a given httpserver will possess a "bind_addr" attribute. So we'd either need to add that to the API (which is fine, just needs to be decided) or use some other method of passing that information back up to the Server object.

If we did add a "bind_addr" requirement, that would mean we could stop using a dict for httpservers and use a list instead (and consumers could inspect [server.bind_addr for server in httpservers] if they cared). That might be the way to go.

10/26/07 02:13:58: Modified by fumanchu

  • milestone changed from 3.0 to 3.2.

Hosted by WebFaction

Log in as guest/cpguest to create tickets