48 Commits

Author SHA1 Message Date
benoitc
1e49846ae5 fix handle_errors 2013-12-27 11:44:21 +01:00
benoitc
95efe1b7d2 add worker_int callback
fix #516
2013-12-26 12:26:07 +01:00
benoitc
feb86d3fb2 don't display the traceback in the HTTP response 2013-09-27 09:09:15 +02:00
benoitc
4e3428af0e add -e/--env command line argunment
This command line argunment allows someone to pass an environement variable to
gunicorn:

	$ gunicorn --env FOO=1 test:app

With the command line above the application will be able to use the FOO
environment vatriable.
2013-08-27 13:21:53 +02:00
Philip Cristiano
dcfe825346 Rename post_init for greater clarity
Makes sense if you saw what it does, less if you just read the config option.
2013-06-20 19:40:03 -04:00
Philip Cristiano
0ae7fd760d Add post-init hook for workers
Allows a config specifying a function after a worker has been initialized and before the run loop
2013-06-20 17:39:46 -04:00
Adnane Belmadiaf
20cd49595a PEP8 fixes 2012-12-24 09:53:03 +01:00
benoitc
b7b51adf13 allows gunicorn to bind to multiple address
Allows gunicorn to listen on different interface. It can be either ipv6,
unix or ipv4 sockets.

Ex:

    gunicorn -w3 -b 127.0.0.1:8001 -b 127.0.0.1:8000 -b [::1]:8000 test:app

fix #444
2012-12-14 10:18:39 +01:00
benoitc
46e041b9f1 don't use map 2012-11-16 11:08:02 +01:00
benoitc
bb9ddb4ca9 Revert "Set timeout for client socket (slow client DoS)."
This changes introduced an issue with websockets support (#432) and is
probably related to #428 & #416 . It is safer for now to revert it.

This reverts commit aa22115cfc9c2b76c818ce231089b01c690052b6.

Conflicts:
	gunicorn/workers/async.py
	gunicorn/workers/sync.py
2012-11-06 05:33:29 +01:00
benoitc
8d453fb341 all tests pass under python 3 2012-10-24 22:07:35 +02:00
Konstantin Kapustin
70534acde8 Implantation proxy protocol 2012-09-27 19:14:40 +02:00
Konstantin Kapustin
aa22115cfc Set timeout for client socket (slow client DoS). 2012-09-27 19:14:40 +02:00
Konstantin Kapustin
4be3282440 Check Content-Length header.
For not chunked request do validation Content-Length header and return 400 if invalid.
2012-09-27 19:14:40 +02:00
benoitc
b85cf2852b close #365 2012-06-24 12:13:05 +02:00
Konstantin Kapustin
9dba6bf7ec Small correct for handle_error.
1. client.getpeername() can raise "error: [Errno 107] Transport endpoint
is
not connected" if a client has unexpectedly disconnected.

2. I guess we do not need worry about sending error message to client.
2012-06-24 11:29:04 +02:00
benoitc
c84b74957b useless 2012-06-04 21:24:32 +02:00
benoitc
118c571898 fix issue #348 .
Rather than testing the parent pd, test if the parent pid is still
alive. Only use it in gevent for now.
2012-06-04 21:17:11 +02:00
Konstantin Kapustin
3ff895d735 Added missing LimitRequestLine and LimitRequestHeader. 2012-05-25 12:52:02 +02:00
Benoit Chesneau
5f11713678 log HTTP errors in access log. close #317 2012-04-26 18:17:55 +02:00
Konstantin Kapustin
ac223ae639 Change logging in handle_error. 2012-03-27 17:01:40 -07:00
benoitc
fa341c6531 pyflakes pass. 2012-02-21 14:53:17 +01:00
benoitc
7a1c58f236 test number of headers fields and size.
Add --limit-request-fields (limit_request_fields) and
--limit-request-field-size (limit-request-field-size) options.

- limit_request_fields:

    Value is a number from 0 (unlimited) to 32768. This parameter is
    used to limit the number of headers in a request to prevent DDOS
    attack. Used with the `limit_request_field_size` it allows more
    safety.

- limit_request_field_size:

    Value is a number from 0 (unlimited) to 8190. to set the limit
    on the allowed size of an HTTP request header field.
2012-02-20 10:36:13 +01:00
benoitc
b7b0979ad9 check if Request Line is too large.
You can now pass the parameter --limit-request-line or set the
limit_request_line in your configuration file to set the max size of the
request line in bytes.

This parameter is used to limit the allowed size of a client's HTTP
request-line. Since the request-line consists of the HTTP method, URI,
and protocol version, this directive places a restriction on the length
of a request-URI allowed for a request on the server. A server needs
this value to be large enough to hold any of its resource names,
including any information that might be passed in the query part of a
GET request. By default this value is 4094 and can't be larger than
8190.

This parameter can be used to prevent any DDOS attack.
2012-02-20 09:56:06 +01:00
benoitc
f168a21dae fix whitespaces 2012-02-19 11:27:46 +01:00
Randall Leeds
4633d1aad9 keep graceful shutdown from interrupting workers
When the signal.siginterrupt call is available it can be used to make
interrupted system calls (errno == EINTR) retry transparently whenever
they have not caused any side effects yet (e.g. no data read/written).
It should make shutdown more graceful.

Patch by Jonas Borgström
2011-09-15 16:20:06 -07:00
benoitc
66f7271c5f Use our own logger object to log events in gunicorn. While I'm here add
the possibility to manage an access log compatible with apache combined
log format. reopening files is also handled. Also, this change fix
issues #237 and #190.

For the sake of simplicity logging file have been removed

--logfile option has become --error-logfile, by default "-"

Following options have been added:

--access-logfile, the access log file path. By default None. If set
access logs will bre written to defined output

eg:

$ gunicorn -w3 --access-logfile=- test:app
2011-08-21 19:36:52 [84572] [INFO] Starting gunicorn 0.13.0
2011-08-21 19:36:52 [84572] [INFO] Listening at: http://127.0.0.1:8000
(84572)
2011-08-21 19:36:52 [84572] [INFO] Using worker: sync
2011-08-21 19:36:52 [84573] [INFO] Booting worker with pid: 84573
2011-08-21 19:36:52 [84574] [INFO] Booting worker with pid: 84574
2011-08-21 19:36:52 [84575] [INFO] Booting worker with pid: 84575
127.0.0.1 - - [21/Aug/2011:19:37:04] "GET / HTTP/1.1" 200 14 "-"
"curl/7.21.4 (universal-apple-darwin11.0) libcurl/7.21.4 OpenSSL/0.9.8r
zlib/1.2.5"
2011-08-21 21:08:58 +02:00
Alex Robbins
974698671a Moved the random seed method into a function.
Added a try/except block to catch NotImplementedErrors for platforms
that don't support urandom.
2011-03-14 23:10:09 -04:00
Paul J. Davis
894e2d2526 Missing spaces in the error response. 2011-03-03 12:02:08 -05:00
benoitc
3fc530c162 this is just a warning, we don't really care about exceptions here. 2011-03-03 10:45:23 +01:00
Paul J. Davis
0c05de4d2b Fixed a couple harmless typos.
Thanks to Josh Ourisman for spotting them.
2011-02-15 14:51:03 -05:00
Paul J. Davis
885b530e1a Always log exceptions during request handling.
* Always log the exception locally
  * Still only pass the exception in the HTTP response if
    debug is turned on.
  * Slight cosmetic changes to the actual HTML of the error
    response.
2011-01-29 14:43:18 -05:00
benoitc
7e6beaf8e7 don't display broken pipe 2010-12-22 23:07:27 +01:00
benoitc
16fd5d3c20 remove some useless code. pyflakes my friend. 2010-12-22 19:52:34 +01:00
benoitc
3ef8688fcc fix issue #137. Use our own way to unlink temporary files so we can set
permissions and umask on it.
2010-12-20 13:51:03 +01:00
benoitc
a8e34ac16c send appropriate error status on http parsing. Fix issue #132. 2010-12-12 14:16:31 +01:00
benoitc
ac1688fe9b fix temporary file leaking . 2010-11-20 16:51:52 +01:00
Paul J. Davis
7e4ca4b809 Implementation of the max-requests feature.
Works on sync and eventlet works. Doesn't work on gevent_pywsig or
gevent_wsgi workers as we don't control their main loops. Tornado
workers appear to be broken.

Worst of all, this causes vanilla gevent workers to segfault. I'm
waiting to see if there's a known issue before considering what to
do next. Worst case we could refuse to run with the bad combination
of settings.
2010-09-01 11:32:26 +02:00
Paul J. Davis
abb4f2a765 Reseed the random number generator after fork().
Web applications use random numbers for things like sessions, if
we don't reseed then each worker will generate the same sequence
of random numbers which can lead to security concerns.

Thanks to Jonas Borgström for the patch.
2010-08-19 19:01:16 -04:00
Paul J. Davis
12f8215e04 Avoid infinite loops spawning workers.
I noticed with preload that if a worker fails to boot the arbiter will
dutifully respawn it. Only to watch it die again. This patch makes it so
if a worker process exits before making it to the run loop the process
will exit with a special exit code. When the arbiter sees this flag it
will shutdown all processes assuming there is an unrecoverable error.
2010-05-25 19:54:33 -04:00
benoitc
62540cffaa commit changes from @davisp + some fixes 2010-05-22 21:11:25 +02:00
benoitc
f7c91e7e86 load after forking 2010-05-22 20:07:08 +02:00
benoitc
776b158683 add preload_app setting 2010-05-22 19:53:02 +02:00
benoitc
2bc67cc8b8 better handling of QUIT/HUP soignal to fix issue #49. We want graceful
quit or restart if possible.
2010-05-10 12:25:34 +02:00
benoitc
ba06498d7d fix issue #47 2010-05-09 21:39:45 +02:00
benoitc
8184eb493c add refactor gevent support like we did on eventlet. In the future it
may be better to use Event object. While i'm here move the monkey
patching in its own function used on config so we make sure to patch
only one time and prevent some ugly hack like reinit gevent each time we
spawn (it's better to use patched os.fork from gevent once time).
2010-04-22 14:38:49 +02:00
Paul J. Davis
0c935d06c7 Got the Sync and Eventlet workers running. 2010-04-15 21:20:17 -04:00
Paul J. Davis
51f1f22665 Refactoring worker code.
Also went through gunicorn.main lightly.
2010-04-15 20:08:28 -04:00