Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RuntimeError: unable to perform operation on UnixTransport #1130

Closed
mohammadhzp opened this issue Feb 17, 2018 · 4 comments
Closed

RuntimeError: unable to perform operation on UnixTransport #1130

mohammadhzp opened this issue Feb 17, 2018 · 4 comments

Comments

@mohammadhzp
Copy link

Hello
It causes a series of exceptions

Full error output is :

Task exception was never retrieved
future: <Task finished coro=<Sanic.handle_request() done, defined at /usr/local/lib/python3.6/site-packages/sanic/app.py:519> exception=AttributeError("'NoneType' object has no attribute 'getpeername'",) created at /usr/local/lib/python3.6/site-packages/sanic/server.py:299>
source_traceback: Object created at (most recent call last):
  File "main.py", line 68, in <module>
    access_log=False, backlog=8000)
  File "/usr/local/lib/python3.6/site-packages/sanic/app.py", line 648, in run
    serve_multiple(server_settings, workers)
  File "/usr/local/lib/python3.6/site-packages/sanic/server.py", line 686, in serve_multiple
    process.start()
  File "/usr/lib64/python3.6/multiprocessing/process.py", line 105, in start
    self._popen = self._Popen(self)
  File "/usr/lib64/python3.6/multiprocessing/context.py", line 223, in _Popen
    return _default_context.get_context().Process._Popen(process_obj)
  File "/usr/lib64/python3.6/multiprocessing/context.py", line 277, in _Popen
    return Popen(process_obj)
  File "/usr/lib64/python3.6/multiprocessing/popen_fork.py", line 26, in __init__
    self._launch(process_obj)
  File "/usr/lib64/python3.6/multiprocessing/popen_fork.py", line 80, in _launch
    code = process_obj._bootstrap()
  File "/usr/lib64/python3.6/multiprocessing/process.py", line 258, in _bootstrap
    self.run()
  File "/usr/lib64/python3.6/multiprocessing/process.py", line 93, in run
    self._target(*self._args, **self._kwargs)
  File "/usr/local/lib/python3.6/site-packages/sanic/server.py", line 609, in serve
    loop.run_forever()
  File "/usr/local/lib/python3.6/site-packages/sanic/server.py", line 220, in data_received
    self.parser.feed_data(data)
  File "/usr/local/lib/python3.6/site-packages/sanic/server.py", line 289, in on_message_complete
    self.execute_request_handler()
  File "/usr/local/lib/python3.6/site-packages/sanic/server.py", line 299, in execute_request_handler
    self.stream_response))
Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/sanic/server.py", line 339, in write_response
    self.keep_alive_timeout))
  File "uvloop/handles/stream.pyx", line 636, in uvloop.loop.UVStream.write
  File "uvloop/handles/handle.pyx", line 165, in uvloop.loop.UVHandle._ensure_alive
RuntimeError: unable to perform operation on <UnixTransport closed=True reading=False 0x7f00061252a8>; the handler is closed

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib64/python3.6/asyncio/coroutines.py", line 126, in send
    return self.gen.send(value)
  File "/usr/local/lib/python3.6/site-packages/sanic/app.py", line 590, in handle_request
    write_callback(response)
  File "/usr/local/lib/python3.6/site-packages/sanic/server.py", line 349, in write_response
    self.request.ip)
  File "/usr/local/lib/python3.6/site-packages/sanic/request.py", line 172, in ip
    self._get_address()
  File "/usr/local/lib/python3.6/site-packages/sanic/request.py", line 188, in _get_address
    self._socket = (self.transport.get_extra_info('peername') or
  File "uvloop/handles/basetransport.pyx", line 320, in uvloop.loop.UVBaseTransport.get_extra_info
AttributeError: 'NoneType' object has no attribute 'getpeername'

Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/sanic/server.py", line 178, in response_timeout_callback
    raise ServiceUnavailable('Response Timeout')
sanic.exceptions.ServiceUnavailable: Response Timeout

This is how I start Sanic:

def bind_unix_socket(s_p):
    if os.path.exists(s_p):
        os.unlink(s_p)
    sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
    sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
    sock.setblocking(0)
    sock.bind(s_p)
    os.chmod(s_p, 0o777)
    sock.listen(8000)
    return sock

_app.run(sock=bind_unix_socket('/mnt/writable/app.sock'), protocol=CustomServer, workers=os.cpu_count(), debug=True, access_log=False, backlog=8000)

Of course debug is False on production.

Fedora 27, Python3.6 and Sanic 0.7.0
I use Nginx in front of Sanic

Any Idea why this happens ? Is it a bug ?

@yunstanford
Copy link
Member

What does your CustomServer Protocol look like ?
I can't reproduce your issue with default protocol.

@mohammadhzp
Copy link
Author

Sorry for delay
CustomServer only changes two configs

class CustomServer(sanic.server.HttpProtocol):
    def __init__(self, *, loop, request_handler, error_handler, **kwargs):
        kwargs['request_max_size'] = config.SERVER_MAX_CHUNK_SIZE
        kwargs['keep_alive'] = False
        super().__init__(loop=loop, request_handler=request_handler, error_handler=error_handler, **kwargs)

@mohammadhzp
Copy link
Author

Any Idea why this happen and how I'm suppose to prevent it ?
Also config.SERVER_MAX_CHUNK_SIZE is 52428800

@sjsadowski
Copy link
Contributor

This should be resolved as of 0.8.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants