MashaTelyatnikova / protobuf-socket-rpc

Automatically exported from code.google.com/p/protobuf-socket-rpc
MIT License
0 stars 0 forks source link

'Socket is not connected' for every request processed by Python server #10

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
I have a really simple Python server that serves RPC requests coming from a 
Java client (all sides using the RPC implementation from this project). For 
every request processed, an exception is thrown at the very end when the 
server tries to close the connection:

server.py line 95: self.request.shutdown(socket.SHUT_RDWR)
-> error(57, 'Socket is not connected')

I'm using v1.3

Original issue reported on code.google.com by jsill...@gmail.com on 6 Jan 2010 at 2:21

GoogleCodeExporter commented 8 years ago
I couldn't recreate the issue using a python server and java client. Can you 
send me 
code snippet of how you are using the python server?

See the example for correct usage.
http://code.google.com/p/protobuf-socket-
rpc/source/browse/trunk/python/src/example/helloworld/run_server.py

Original comment by sdeo.code@gmail.com on 15 Feb 2010 at 10:45

GoogleCodeExporter commented 8 years ago
[deleted comment]
GoogleCodeExporter commented 8 years ago
I too am experiencing this, even with the helloworld example. I'm on OSX 
Leopard. 
Here's the traceback:

----------------------------------------
Exception happened during processing of request from 
('127.0.0.1'----------------------------------------
, 57451)
Traceback (most recent call last):
Exception happened during processing of request from ('127.0.0.1', 57452)
Traceback (most recent call last):
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/SocketServer.py", line 558, in 
process_request_thread
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/SocketServer.py", line 558, in 
process_request_thread
    self.finish_request(request, client_address)
    self.finish_request(request, client_address)
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/SocketServer.py", line 320, in 
finish_request
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/SocketServer.py", line 320, in 
finish_request
    self.RequestHandlerClass(request, client_address, self)
    self.RequestHandlerClass(request, client_address, self)
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/SocketServer.py", line 615, in 
__init__
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/SocketServer.py", line 615, in 
__init__
    self.handle()
    self.handle()
  File "../../main/protobuf/server.py", line 95, in handle
  File "../../main/protobuf/server.py", line 95, in handle
    self.request.shutdown(socket.SHUT_RDWR)
    self.request.shutdown(socket.SHUT_RDWR)
  File "<string>", line 1, in shutdown
  File "<string>", line 1, in shutdown
error: [Errno 57] Socket is not connected
----------------------------------------

Original comment by alecatho...@gmail.com on 25 Feb 2010 at 5:24

GoogleCodeExporter commented 8 years ago
I dealt with this by wrapping the shutdown in a try/except and explicitly 
testing or errno 
= 57. I am not convinced this is the right thing to do, but it at least stopped 
spamming 
me.

Original comment by a...@google.com on 27 Feb 2010 at 8:54

GoogleCodeExporter commented 8 years ago
As far as I can understand, looks like the connection is already closed by the 
client (at least one way!). So in 
the server you can do the following if you don't like replacing the *shutdown* 
call with *close*. 

file: server.py

class SocketHandler(SocketServer.StreamRequestHandler):
    '''Handler for service requests.'''

    def handle(self):
        '''Entry point for handler functionality.'''
        log.debug('Got a request')

        # Parse the incoming request        
        recv = self.rfile.read()

        # Evaluate and execute the request
        rpcResponse = self.validateAndExecuteRequest(recv)
        log.debug("Response to return to client \n %s" % rpcResponse)

        # Send reply to client
        self.wfile.write(rpcResponse.SerializeToString())
        self.request.shutdown(socket.SHUT_WR)
        self.request.close()

IMHO, the operations prior to the socket close should be in a *try* block with 
the shutdown and close 
enclosed in an accompanying *finally* block. 

Original comment by timid.Ge...@gmail.com on 9 May 2010 at 7:37

GoogleCodeExporter commented 8 years ago
Will you accept a patch for this? Apparently it only happens in OSX but it is 
still happening 4 years after this thread was created.

Original comment by dudassdo...@gmail.com on 21 Oct 2014 at 9:01