Discussion:
Bug#944226: No way to use xheaders in tornado worker
(too old to reply)
Enrico Zini
2019-11-06 11:30:02 UTC
Permalink
Package: gunicorn3
Version: 19.9.0-1
Severity: important

Hello,

thanks for packaging gunicorn.

I am using gunicorn to deploy a tornado server using the tornado worker.
Deployment is behind a proxy, so I need to activate xheaders in the
tornado httpserver[1], and use --forwarded-allow-ips in gunicorn.

In workers/gtornado.py, however, I see no way to set xheaders=True in
the created tornado httpserver. This seems odd because in the traceback
in this link there seems to be or have been code for it:
https://github.com/benoitc/gunicorn/issues/783

I'll now try to explore workarounds, as this is making it impossible to
deploy a tornado server with gunicorn behind a proxy :/

Enrico

[1] https://www.tornadoweb.org/en/stable/httpserver.html#http-server


-- System Information:
Debian Release: 10.1
APT prefers stable
APT policy: (500, 'stable')
Architecture: amd64 (x86_64)

Kernel: Linux 4.19.0-6-amd64 (SMP w/4 CPU cores)
Kernel taint flags: TAINT_WARN, TAINT_OOT_MODULE, TAINT_UNSIGNED_MODULE
Locale: LANG=en_IE.UTF-8, LC_CTYPE=en_IE.UTF-8 (charmap=UTF-8), LANGUAGE=en_IE:en (charmap=UTF-8)
Shell: /bin/sh linked to /usr/bin/dash
Init: systemd (via /run/systemd/system)
LSM: AppArmor: enabled

Versions of packages gunicorn3 depends on:
ii python3 3.7.3-1
ii python3-gunicorn 19.9.0-1

gunicorn3 recommends no packages.

Versions of packages gunicorn3 suggests:
pn gunicorn-examples <none>
pn python3-pastedeploy <none>
ii python3-setproctitle 1.1.10-1+b2
ii python3-tornado 5.1.1-4

-- no debconf information
Enrico Zini
2019-11-06 12:10:01 UTC
Permalink
Post by Enrico Zini
I'll now try to explore workarounds, as this is making it impossible to
deploy a tornado server with gunicorn behind a proxy :/
First (failed) attempt was using a python configuration with this hook:

def post_worker_init(worker):
worker.server.xheaders = True

however, at the time the hook is called, worker.server is not filled,
and it is only filled in the TornadoWorker.run() method, which does not
terminate and so cannot be extended. There seem to be no obvious way to
hook into tornado.httpserver.HTTPServer creation inside TornadoWorker.

I found a non-obvious way, monkey patching tornado.httpserver.HTTPServer
to default to xheaders=True:

def post_worker_init(worker):
import tornado.httpserver

class XheadersServer(tornado.httpserver.HTTPServer):
def __init__(self, *args, **kw):
super().__init__(*args, **kw)
self.xheaders = True

tornado.httpserver.HTTPServer = XheadersServer

This way it seems to work.


Enrico
--
GPG key: 4096R/634F4BD1E7AD5568 2009-05-08 Enrico Zini <***@enricozini.org>
Chris Lamb
2019-11-06 19:10:01 UTC
Permalink
Hi Enrico,
Post by Enrico Zini
I found a non-obvious way, monkey patching tornado.httpserver.HTTPServer
Ooh, how delightful. ;)

Would you like me to forward this issue upstream or would you be able
to do that? (I don't think this is something that Debian should change
independent of upstream, at least unless there was some kind of
disagreement over the fix…)


Best wishes,
--
,''`.
: :' : Chris Lamb
`. `'` ***@debian.org 🍥 chris-lamb.co.uk
`-
Enrico Zini
2019-11-08 17:30:02 UTC
Permalink
Post by Chris Lamb
Post by Enrico Zini
I found a non-obvious way, monkey patching tornado.httpserver.HTTPServer
Ooh, how delightful. ;)
Would you like me to forward this issue upstream or would you be able
to do that? (I don't think this is something that Debian should change
independent of upstream, at least unless there was some kind of
disagreement over the fix
)
Thanks, done: https://github.com/benoitc/gunicorn/issues/2156`


Enrico
--
GPG key: 4096R/634F4BD1E7AD5568 2009-05-08 Enrico Zini <***@enricozini.org>
Loading...