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

When using Nginx with wsgi protocol, workers end with "WORKER TIMEOUT" #3296

Closed
braiam opened this issue Sep 16, 2024 · 3 comments
Closed

When using Nginx with wsgi protocol, workers end with "WORKER TIMEOUT" #3296

braiam opened this issue Sep 16, 2024 · 3 comments

Comments

@braiam
Copy link

braiam commented Sep 16, 2024

With the following app:

def app(environ, start_response):
  data = b"Hello, World!\n"
  start_response("200 OK", [
    ("Content-Type", "text/plain"),
    ("Content-Length", str(len(data)))
  ])
  return iter([data])

and configuring nginx this way (in sites-enabled/<file>):

upstream app_server {
    server 127.0.0.1:8000 fail_timeout=0;
}
server {
    listen 80;
 
    keepalive_timeout 5;

    location / {
      include /etc/nginx/uwsgi_params;
      uwsgi_pass app_server;
      uwsgi_param Host $host;
      uwsgi_param X-Real-IP $remote_addr;
      uwsgi_param X-Forwarded-For $proxy_add_x_forwarded_for;
      uwsgi_param X-Forwarded-Proto $http_x_forwarded_proto;
    }
}

Starting gunicorn with gunicorn wsgi:app --bind localhost:8000, results in the following:

$ gunicorn wsgi:app --bind localhost:8000                  
[2024-09-16 11:15:34 -0400] [780833] [INFO] Starting gunicorn 23.0.0
[2024-09-16 11:15:34 -0400] [780833] [INFO] Listening at: http://127.0.0.1:8000 (780833)
[2024-09-16 11:15:34 -0400] [780833] [INFO] Using worker: sync
[2024-09-16 11:15:34 -0400] [780834] [INFO] Booting worker with pid: 780834
[2024-09-16 11:16:08 -0400] [780833] [CRITICAL] WORKER TIMEOUT (pid:780834)
[2024-09-16 11:16:08 -0400] [780834] [INFO] Worker exiting (pid: 780834)
[2024-09-16 11:16:08 -0400] [780833] [ERROR] Worker (pid:780834) exited with code 1
[2024-09-16 11:16:08 -0400] [780833] [ERROR] Worker (pid:780834) exited with code 1.
[2024-09-16 11:16:08 -0400] [781161] [INFO] Booting worker with pid: 781161

Log level debug doesn't reveal more information about why the worker died. Using an http request directly to the port 8000 it works correctly.

This is related to #3207

@braiam
Copy link
Author

braiam commented Sep 16, 2024

As an aside, I tested this same configuration with uwsgi using uwsgi --plugin /usr/lib/uwsgi/plugins/python312_plugin.so -s localhost:8000 --wsgi-file wsgi.py and it worked correctly.

@braiam
Copy link
Author

braiam commented Sep 16, 2024

The uwsgi_params file has this content:

uwsgi_param  QUERY_STRING       $query_string;
uwsgi_param  REQUEST_METHOD     $request_method;
uwsgi_param  CONTENT_TYPE       $content_type;
uwsgi_param  CONTENT_LENGTH     $content_length;

uwsgi_param  REQUEST_URI        $request_uri;
uwsgi_param  PATH_INFO          $document_uri;
uwsgi_param  DOCUMENT_ROOT      $document_root;
uwsgi_param  SERVER_PROTOCOL    $server_protocol;
uwsgi_param  REQUEST_SCHEME     $scheme;
uwsgi_param  HTTPS              $https if_not_empty;

uwsgi_param  REMOTE_ADDR        $remote_addr;
uwsgi_param  REMOTE_PORT        $remote_port;
uwsgi_param  SERVER_PORT        $server_port;
uwsgi_param  SERVER_NAME        $server_name;

@braiam
Copy link
Author

braiam commented Sep 17, 2024

I used the reference implementation of wsgiref with the small example in the documentation which hinted at the problem. I was thoroughly confused by Nginx documentation that configures uwsgi binary protocol, which gunicorn doesn't support. It is still a good method to trigger the related timeout issue.

@braiam braiam closed this as completed Sep 17, 2024
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

1 participant