Issues with socket reuse on Windows

51 views
Skip to first unread message

Nicholas Riley

unread,
Aug 20, 2016, 2:03:54 PM8/20/16
to rpyc

I use RPyC to listen for connections on Windows in a way that needs to stay single threaded (no more than one simultaneous connection). Therefore, for several years I have been using it as follows:


      from rpyc.utils.server import OneShotServer

        while DragonService.should_keep_serving:

            OneShotServer(DragonService, port=9999).start()


This has worked for a while, but at some point recently, I have started getting errors as follows:


07/25 10:35:01.137 ERROR root: Uncaught exception

Traceback (most recent call last):

  File "C:\NatLink\DragonControl\dictation_server.pyw", line 274, in <module>

    OneShotServer(DragonService, port=9999).start()

  File "C:\Python26\lib\site-packages\rpyc-3.3.0-py2.6-win32.egg\rpyc\utils\server.py", line 78, in __init__

    self.listener.bind((hostname, port))

  File "<string>", line 1, in bind

error: [Errno 10048] Only one usage of each socket address (protocol/network address/port) is normally permitted


On Unix-like OSes (where I have much more experience) that would usually mean I forgot to set SO_REUSEADDR, but I see the following in RPyC’s source:


            if reuse_addr and sys.platform != "win32":

                # warning: reuseaddr is not what you'd expect on windows!

                # it allows you to bind an already bound port, resulting in "unexpected behavior"

                # (quoting MSDN)

                self.listener.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)


Anyone else run into anything similar?  I’m trying another workaround at the moment (seeing if setting backlog=0 will help as I'd prefer the client side just fail immediately rather than hang when the server is in use), but may see about bypassing that check to see if it helps.  Unfortunately this error isn’t easily reproducible; it only happens once every few days in my usage, so I’ll have to keep testing.


—Nicholas

Reply all
Reply to author
Forward
0 new messages