72 Commits

Author SHA1 Message Date
William Pitcock
448bb0a94d use EnvironmentError instead of socket.error 2016-02-01 09:57:27 -05:00
Randall Leeds
14bbd1cfce comment formatting 2014-11-12 13:06:02 -08:00
Randall Leeds
96a15b38a8 Merge pull request #931 from laterpay/feature/921-ignore-async-handle_request-socket-error
Feature/921 ignore async handle request socket error
2014-11-12 13:05:09 -08:00
Jonas Maurus
fbc1e29c72 use six.reraise to amend the traceback 2014-11-12 09:50:10 +00:00
Jonas Maurus
d0f1ff659f fix #921 by passing socket.error on to the caller (where it will be ignored) 2014-11-11 10:13:09 +00:00
wong2
f8902a6837 propagate proxy_protocol_info to keep-alive requests correctly, fix #923 2014-11-06 14:48:16 +08:00
bninja
adf353f213 propagate proxy_protocol_info to keep-alive requests, fixes #899 2014-09-24 03:39:39 -07:00
benoitc
f41f86c3da StopIteration shouldn't be catched at this level.
fix #790
2014-06-14 21:46:35 +02:00
Matt Billenstein
bc41bad2d6 workers/async.py - handle_request takes listener_name instead of listener
AFAICT - this should have been updated in 62f6fb2d
2014-06-04 18:18:28 -07:00
bninja
62f6fb2d33 save listener socket name so we can handle buffered keep-alive requests *after*
listener has been closed (i.e. stopped accepting during worker teardown)
2014-06-01 10:07:43 +02:00
benoitc
0e4d9f0378 make sure we return the correct error with the last traceback.
fix #630
2014-03-08 18:01:30 -08:00
Randall Leeds
b981014acc Log exceptions that occur after response start
Fix #694
2014-02-06 19:31:22 -08:00
Randall Leeds
56b5f4038f set wsgi.multithread to True for async workers
Also simplifies the environment handling in the gevent_pywsgi
server so that it also has this key. An added side effect is
that the gunicorn FileWrapper gets set for the gevent_pywsgi
worker, too.

Fixes #486
2014-01-01 16:42:56 +01:00
benoitc
40bc38bb2f support wsgi.file_wrapper in async workers 2013-08-27 11:17:03 +02:00
Randall Leeds
fa9d028d09 After closing for error do not keep alive
Raise a StopIteration rather than returning so that the keep-alive
loop is terminated. If gunicorn has closed the socket there is no
sense in trying to read another request and it may cause spurious
EBADF errors to try.
2013-08-07 19:57:56 -07:00
py
b4c286bc81 resp maybe None when pre_request raise exceptions 2013-07-30 17:27:51 +08:00
benoitc
e77d47cb97 don't raise an error when we close the socket.
fix #537
2013-06-05 10:44:20 +02:00
Alexandre Zani
12ec996d54 Close connection on error after sending started.
When the application starts yielding a body and then raises an error,
we should immediately close the connection to the client to indicate
the error.
2013-04-21 15:01:18 +02:00
Adnane Belmadiaf
20cd49595a PEP8 fixes 2012-12-24 09:53:03 +01:00
Konstantin Enchant
aac56c9d55 Added response arg for post_request hook. 2012-12-16 10:21:01 +01:00
benoitc
1198cc2723 handle ssl connections.
gunicorn is now supporting ssl connections:

    $ gunicorn -w3 --certfile=server.crt --keyfile=server.key test:app

works with all supported workers
2012-12-14 10:22:05 +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
6f726e0ec9 make sure to catch EPIPE and ECONNRESET error 2012-11-13 09:52:37 +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
benoitc
53ce50bc7b obvious syntax fixes preparing python3 support 2012-10-24 12:11:15 +02:00
Konstantin Kapustin
aa22115cfc Set timeout for client socket (slow client DoS). 2012-09-27 19:14:40 +02:00
benoitc
5615464923 handle keepalive = 0
Keepalive=0 means that we aren't waiting for the next connection. So
make sure to send appropriate "close" header and that we handle the first
connection.
2012-07-04 09:34:12 +02:00
benoitc
d79ff999ce fix multiple issues with request limit
patch from Djoume Salvetti . address the following issues in gunicorn:

* Gunicorn does not limit the size of a request header (the
* limit_request_field_size configuration parameter is not used)

* When the configured request limit is lower than its maximum value, the
* maximum value is used instead. For instance if limit_request_line is
* set to 1024, gunicorn will only limit the request line to 4096 chars
* (this issue also affects limit_request_fields)

* Request limits are not limited to their maximum authorized values. For
* instance it is possible to set limit_request_line to 64K (this issue
* also affects limit_request_fields)

* Setting limit_request_fields and limit_request_field_size to 0 does
* not make them unlimited. The following patch allows limit_request_line
* and limit_request_field_size to be unlimited. limit_request_fields can
* no longer be unlimited (I can't imagine 32K fields to not be enough
* but I have a use case where 8K for the request line is not enough).

* Parsing errors (premature client disconnection) are not reported

* When request line limit is exceeded the configured value is reported
* instead of the effective value.
2012-05-24 12:13:34 +02:00
Benoit Chesneau
5f11713678 log HTTP errors in access log. close #317 2012-04-26 18:17:55 +02:00
benoitc
1319543448 use the cached app. 2012-03-01 08:02:15 +01:00
benoitc
5a7c756a98 close #304 .
Intoduce a change in log access format:

- request headers are now added to the log format using the
  {HeaderName}i variable
- response headers are now handled using the {HeaderName}o variables
- headers name are insensitive
- non existent keys in the log access format are replaced by '-'
2012-02-25 14:44:38 +01:00
benoitc
161c8c03cb monkey patch django. close #293 .
This patch make sure that we use real threads to get the ident which is
going to happen if we are using gevent or eventlet.
2012-02-21 14:24:55 +01:00
benoitc
6766c14793 pass config to the http parser. 2012-02-20 07:02:55 +01:00
benoitc
f168a21dae fix whitespaces 2012-02-19 11:27:46 +01:00
Randall Leeds
b955407003 better logging on http parse errors
NoMoreData now inherits StopIteration and the StopIteration clause in
the workers logs the reason at debug level.
2011-11-07 14:56:59 -08:00
Randall Leeds
04680f1020 fix inverted request_time computation 2011-09-18 02:13:01 -07:00
benoitc
571a5309d1 - add request time support in log access
- make log access format customizable in settings:
- fix logger

To setup a log format use the --access-logformat option.

        By default:

        %(h)s %(l)s %(u)s %(t)s "%(r)s" %(s)s %(b)s "%(f)s" "%(a)s"

        h: remote address
        t: date of the request
        r: status line (ex: GET / HTTP/1.1)
        s: status
        b: response length or '-'
        f: referer
        a: user agent
        T: request time in seconds
        D: request time in microseconds

        You can also pass any WSGI request header as a parameter.
        (ex '%(HTTP_HOST)s').
2011-09-09 01:44:31 +02:00
benoitc
2375ca87fe fix issue #244. lats change in post_request arity was breaking some apps
and also wasn't working everywhere. This patch wrap the function if
arity != 3 so we don't have to test its arity each time we use it.
2011-09-09 00:11:02 +02: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
Randall Leeds
21f7282128 remove redundant exception handling an async base
StopIteration is simply propogated, so there's no reason to catch it.
The catch-all exception is also caught and logged in handle(), but
broken pipe errors are ignored. The redundant catch here was generating
excess logging by calling handle_error for a broken pipe which fails to
send the error because the client has already disconnected.
2011-07-08 14:38:32 -07:00
Graham Dumpleton
b7adfe2628 Add wsgi.file_wrapper optimisations for MacOS X/Linux. 2011-03-23 07:37:40 +01:00
Paul J. Davis
cdd58014a7 Prevent exceptions from being logged twice.
* Remove logging call in worker subclasses and rely on the
    logging in Worker.handle_error to do the proper logging.
2011-01-29 16:40:25 -05:00
Paul J. Davis
f942b3a8b2 Fix broken chunked response generation.
* Transfer-Encoding header was not being set.
* Whether a connection should close should depend on whether
  we are able to continue accepting requests.
2011-01-14 19:24:21 -05:00
benoitc
16fd5d3c20 remove some useless code. pyflakes my friend. 2010-12-22 19:52:34 +01:00
benoitc
a8e34ac16c send appropriate error status on http parsing. Fix issue #132. 2010-12-12 14:16:31 +01:00
Paul J. Davis
011ae33c0a Make sure that post_request is called.
Fixes #119
2010-11-03 13:28:48 -04:00
benoitc
4ed9901708 fix max-requests from @davisp and me, reviewed by @davisp 2010-09-02 21:59:02 +02: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
benoitc
7300502605 dramatically improve eventlet worker 2010-08-12 12:18:41 +02:00