benoitc / gunicorn

gunicorn 'Green Unicorn' is a WSGI HTTP Server for UNIX, fast clients and sleepy applications.
http://www.gunicorn.org
Other
9.89k stars 1.76k forks source link

Gunicorn - Exception in worker process - OSError: [Errno 14] Bad address #1546

Closed alison-f-cooper closed 7 years ago

alison-f-cooper commented 7 years ago

I'm able to run my Flask app locally using Docker, with the following command in my Dockerfile:

CMD ["gunicorn", "-w", "20", "-b", "0.0.0.0:5000", "--capture-output", "--enable-stdio-inheritance", "--access-logfile", "-", "app:app"]

However, upon attempting to deploy the application to a test server, there is an exception in the worker process, and it crashes:

Exception in worker process:
Traceback (most recent call last):
  File "/usr/local/lib/python3.5/site-packages/gunicorn/arbiter.py", line
502, in spawn_worker
    worker.init_process()
  File "/usr/local/lib/python3.5/site-packages/gunicorn/workers/base.py",
line 114, in init_process
    self.wsgi = self.app.wsgi()
  File "/usr/local/lib/python3.5/site-packages/gunicorn/app/base.py", line
66, in wsgi
    self.callable = self.load()
  File "/usr/local/lib/python3.5/site-packages/gunicorn/app/wsgiapp.py",
line 65, in load
    return self.load_wsgiapp()
  File "/usr/local/lib/python3.5/site-packages/gunicorn/app/wsgiapp.py",
line 52, in load_wsgiapp
    return util.import_app(self.app_uri)
  File "/usr/local/lib/python3.5/site-packages/gunicorn/util.py", line 356,
in import_app
    __import__(module)
  File "/code/app/__init__.py", line 2, in <module>
    from flask_alchy import Alchy
  File "/usr/local/lib/python3.5/site-packages/flask_alchy.py", line 8, in
<module>
    from flask_sqlalchemy import SQLAlchemy
  File
"/usr/local/lib/python3.5/site-packages/flask_sqlalchemy/__init__.py", line
18, in <module>
    import sqlalchemy
  File "/usr/local/lib/python3.5/site-packages/sqlalchemy/__init__.py", line
9, in <module>
    from .sql import (
  File "/usr/local/lib/python3.5/site-packages/sqlalchemy/sql/__init__.py",
line 98, in <module>
    __go(locals())
  File "/usr/local/lib/python3.5/site-packages/sqlalchemy/sql/__init__.py",
line 96, in __go
    from . import naming
  File "/usr/local/lib/python3.5/site-packages/sqlalchemy/sql/naming.py",
line 15, in <module>
    from .. import event, events
  File "/usr/local/lib/python3.5/site-packages/sqlalchemy/events.py", line
12, in <module>
    from .engine import Connectable, Engine, Dialect
  File
"/usr/local/lib/python3.5/site-packages/sqlalchemy/engine/__init__.py", line
54, in <module>
    from .interfaces import (
  File "<frozen importlib._bootstrap>", line 969, in _find_and_load
  File "<frozen importlib._bootstrap>", line 958, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 673, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 658, in exec_module
  File "<frozen importlib._bootstrap_external>", line 763, in get_code
  File "<frozen importlib._bootstrap_external>", line 816, in get_data
OSError: [Errno 14] Bad address

Any idea what's going on here? It looks like it's trying to import the app, is hitting the app's init file, and for some reason is bombing out on some sql alchemy code in the imports section. We import Alchy in our init file, and it's trying to pull in the sql alchemy engine, and just blows up with "Bad Address."

Thanks.

berkerpeksag commented 7 years ago

Thank you for the report. Could try to run Gunicorn with strace? Errno 14 usually means either some invalid value was passed into a syscall or in some cases there was no memory available on the host.

Also, what's the full Python 3.5 and Gunicorn version? Is there any difference between your development machine and production server? Did you get the same error without using Docker? Could you try to run a simpler app on your production server (with using Docker) You can use https://github.com/benoitc/gunicorn/blob/master/examples/test.py as a test app.

alison-f-cooper commented 7 years ago

Hi there -- I upgraded our gunicorn version to 19.7, and got some more precise output with debug logging. It looks like the problems are related to this:

https://github.com/benoitc/gunicorn/issues/1194

I will be continuing the conversation on that thread, since it seems a lot of folks are running into similar issues.

Thanks.