[PEAK] tools.server.url

Phillip J. Eby pje at telecommunity.com
Tue Oct 19 15:50:03 EDT 2004


At 03:28 PM 10/17/04 -0600, Wayne Larsen wrote:

>With a fixed port, I run into the following exception all the time:
>
>   File "/Users/waynelarsen/Development/PEAK/src/peak/net/sockets.py", 
> line 196, in <lambda>
>     lambda o: o.listen_sockets(maxsocks=1)[0],
>   File "/Users/waynelarsen/Development/PEAK/src/peak/net/sockets.py", 
> line 67, in listen_sockets
>     raise socket.error, msg
>socket.error: (48, 'Address already in use')

Is it really "all the time"?  Or just when you re-run the program within a 
short time interval?


>The following patch prevents that from being an issue:
>
>--- sockets.py  5 Jul 2004 23:41:50 -0000       1.14
>+++ sockets.py  17 Oct 2004 21:27:51 -0000
>@@ -55,6 +55,7 @@
>                      except OSError,v:
>                          if v<>errno.ENOENT: # ignore if socket doesn't exist
>                              raise
>+                s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
>                  s.bind(sa)
>                  s.listen(5) # should will be made configurable
>                  sockets.append(s)

Ugh.  I don't think this is portable; ISTR Windows has some issues with 
SO_REUSEADDR.  [Googlebreak...]  Yep.  See this:

http://mail.python.org/pipermail/python-dev/2004-August/047812.html

So, I'll have to think about this one.

Also, I'm surprised that using port 0 doesn't work to allocate an available 
port.  That almost seems to me like something's broken in OS/X, but maybe 
it's a general BSD thing.  (Ty: any thoughts on that?  Bob?)

We may need to add some options to the 'listen_sockets' method to allow 
controlling this kind of thing, although ideally it should be done in a 
cross-platform sort of way and with reasonable defaults, otherwise we're 
just pushing the issue into every socket-using piece of code.




More information about the PEAK mailing list