338 Commits

Author SHA1 Message Date
Benoit Chesneau
21ffa92be1 Merge pull request #1394 from jonashaag/master
Add child_exit() callback to configuration
2017-01-27 16:00:58 +01:00
崔志萍
ee47b0030d threadWorker cancelled request should decrease nr_conns (#1387) 2016-12-23 16:02:50 -08:00
Randall Leeds
bc5ae5d457 format boot tracebacks properly with reloader (#1415)
fix #1408
2016-12-23 10:56:07 -08:00
Stefaan Ghysels
9430742ba6 add support for eventlets _AlreadyHandled object (#1406)
add support for eventlets _AlreadyHandled - issue 1210 - Response object has no attribute status_code
2016-12-21 20:48:07 +01:00
Adnane Belmadiaf
ce87a9bd40 Make sure load_wsgi() is called after starting the reloader (#1399)
Fixes #1397
2016-12-12 17:16:53 +03:00
Jonas Haag
f671d51f76 Make Worker.pid useful in master process 2016-11-25 12:16:23 +01:00
Mark Adams
6eb01409da Fix validate_reload by returning the validated value (#1378)
* Fix validate_reload by returning the validated value

When '--reload=RELOADER_TYPE' was implemented, `validate_reload()` was
added but in one of the last refactorings, it lost the return statement
at the end of the function. As a result, the '--reload' config value was
totally broken.

This resolves the issue by adding the missing return.

* Fix tests by changing --reload to always require an argument

- '--reload' always requires an argument now
- Added 'auto' as the default value for '--reload'
2016-10-28 08:35:24 +02:00
Mark Adams
92d48256e4 Modify 'reload' config to be more consistent with existing API
--reload = Runs the reloader with inotify if available and falls back on
           FS polling.
--reload=inotify = Forces the reloader to run with inotify
--reload=poll = Forces the reloader to use FS polling
2016-10-24 11:39:10 -05:00
Mark Adams
64b26ef766 Fix #1368 by adding InotifyReloader and 'use-inotify' configuration option
Currently, '--reload' uses FS polling to find out when files have
changed. For some time, the Linux kernel has had a feature called
inotify that allows applications to monitor for FS events without
polling.

This commit adds a new 'use-inotify' configuration option that will
cause gunicorn to use the new 'InotifyReloader' instead of the default
'Reloader' when 'reload' is enabled.

Using inotify can result in lower CPU consumption by gunicorn especially
when working with virtualized filesystems or environments with a large
number of watched files / directories.
2016-10-17 21:21:37 -05:00
benoitc
cb84e6ed11 initialize the group access list for a worker when initgroups is set
Allows the possibility to initialise the group access list when needed to separate privileges

fix #1287
2016-05-31 18:26:41 +02:00
benoitc
44d3ac8451 gthread: handle removed socket in the select loop
when it happend there are good chance the socket has been removed because it timeouted on the other end. So ignore it.

fix #1258
2016-05-21 00:13:57 +02:00
benoitc
39f62ac66b make sure to remove the signal from the worker pipe
The signal was never removed from the pie which was always waking up the worker
triggering a CPU spike.

fix #1269
2016-05-20 11:40:20 +02:00
benoitc
e5d27516cf makes sure to execute the hook and exit cleanly 2016-05-13 20:25:29 +02:00
benoitc
3cbbc713b1 don't kill ourself on reload
Killing ourself when using the `--reload` option trigger an infinite loop under some monitoring services like the one in pycharm and don't reload the file.

Instead set self.alive as False which will trigger later the worker exit. Note that if we want to force the exit we could also use sys.exit(0) .

fix #1129
2016-05-13 11:09:14 +02:00
benoitc
b0c0333248 unblock the wait loop under python 3.5
in python 3.5 the select is blocking when waiting for it which prevent quick
exit on SIGTERM.

The problem is described:
https://www.python.org/dev/peps/pep-0475/#backward-compatibility

This change fix it by listening for signal event on the worker pipe. Once an
event is triggered it will forcefully wake up the select and return.

fix #1256
2016-05-10 09:08:17 +02:00
benoitc
66546d66df fix #1246 2016-05-02 15:04:30 +02:00
Aleksandr Balezin
95c71cbbfb do post_worker_init after load_wsgi 2016-04-29 17:23:32 +03:00
Randall Leeds
bab8ce016d Merge pull request #1218 from benoitc/gevent-remove-inner-exception-loop
[gevent] remove obsolete exception clauses in run
2016-03-25 13:22:33 -07:00
Randall Leeds
706eb98f33 Merge pull request #1222 from benoitc/fix/922-eventlet-graceful-close
[eventlet] close sockets at graceful shutdown
2016-03-25 13:19:21 -07:00
Randall Leeds
fd8b8e49c6 Merge pull request #1230 from benoitc/fix/922-thread-graceful-close
[thread] close sockets at graceful shutdown
2016-03-25 13:18:47 -07:00
Semyon Maryasin
03a944d668 Fixed traceback formatting 2016-03-24 00:37:12 +03:00
Randall Leeds
f104a0ef20 Merge pull request #1217 from benoitc/eventlet-async-quit
[eventlet] handle QUIT in a new coroutine
2016-03-22 10:37:13 -07:00
Benoit Chesneau
7be2b8d2ba Merge pull request #1231 from benoitc/fix/gh1177
prevent crash when reporting an error
2016-03-22 13:07:30 +01:00
benoitc
1ccebab763 prevent crash when reporting an error
Try to not crash when reporting an error. This changes makes sure we can log the uri and also handle SSL errors.

fix #1177
2016-03-22 11:32:01 +01:00
Randall Leeds
f2418a95e0 [thread] close sockets at graceful shutdown
The run loop has to change slightly to support graceful shutdown.
There is no way to interrupt a call to `futures.wait` so instead
the pattern, used by the async workers, is to sleep for only one
second at the most. The poll is extended to a one second timeout
to match.

Since threads are preemptively scheduled, it's possible that the
listener is closed when the request is actually handled. For this
reason it is necessary to slightly refactor the TConn class to store
the listening socket name. The name is checked once at the start of
the worker run loop.

Ref #922
2016-03-20 17:34:55 -07:00
Paul Fisher
20d3a2d0c9 clean up sys.exc_info calls to drop circular refs 2016-03-19 17:27:58 -07:00
Randall Leeds
48d1e74d01 [eventlet] close sockets at graceful shutdown
Ref #922
2016-03-13 16:57:42 -07:00
Randall Leeds
1388232e38 [gevent] remove obsolete exception clauses in run
Since the changes from #1126, errors are not raised into the main
loop during a non-graceful shutdown. Therefore, these exception
clauses shouldn't be needed anymore.
2016-03-13 14:36:42 -07:00
Randall Leeds
c6387b3031 [eventlet] handle QUIT in a new coroutine
Just like in the gevent worker, a blocking call should only be executed
from within a coroutine. The AssertionError around the main loop of the
eventlet worker can be removed, since it was there to catch
the exception raised by the sleep.
2016-03-13 14:32:43 -07:00
Randall Leeds
d6a47e8aa2 Merge pull request #1193 from urbaniak/gaiohttp-logging
fix access logging in gaiohttp worker
2016-02-02 18:04:40 -08:00
Krzysztof Urbaniak
353508cd8a fix access logging in gaiohttp worker 2016-02-03 00:55:58 +01:00
William Pitcock
448bb0a94d use EnvironmentError instead of socket.error 2016-02-01 09:57:27 -05:00
mtustin-handy
5c2cb816d0 Fix random outdent which makes gtornado worker unusable 2015-11-25 10:41:04 -05:00
Hiroyuki Shirakawa
b4e86ad73f Fixes #1135 2015-10-28 12:04:08 +09:00
Jason Madden
fb96a9ae69 Make the gevent workers handle the quit signal by deferring to a new greenlet. Fixes #1126. 2015-10-15 18:13:35 -05:00
keakon
5708d1d23b remove checking timeouts 2015-10-08 12:20:43 +08:00
tumb1er
21c7e106a3 SSL support for gaiohttp worker
Initialize and pass `SSLContext` to `asyncio.loop.create_server` to enable ssl support.
2015-08-25 16:15:46 +03:00
benoitc
64a5b5cdf3 don't close the unix socket when the worker exit
When the worker was exiting, eventlet is closing the listening socket in th
worker. Since the socket instances are shared, this was also removing the unix
socket on close. This change make sure that the socket can only be closed by
its parent (where the socket have been bound).

While I'm here, also make sure we don't use any blocking function in eventlet
while switching).

fix #965
2015-07-22 06:22:24 +02:00
Wolfgang Schnerring
79011d0c4a
Include request URL in error message.
Fixes #1061.
2015-07-08 10:18:26 +02:00
Krzysztof Urbaniak
66a0fdfd4f add support for gevent on python3 2015-07-04 02:38:54 +02:00
Berker Peksag
e1aa8068e4 Merge pull request #1033 from ccl0326/master
make graceful shutdown thread-safe
2015-05-23 15:49:20 +03:00
陈程龙
d9b89599cc make graceful shutdown thread-safe 2015-05-23 19:00:38 +08:00
Jarmo Hekkanen
826ef2d151 Fix self.nr usage in ThreadedWorker so that auto restart works as expected 2015-05-16 00:36:55 +03:00
Vlad Dragos
342512a128 Add the 'gthread' worker to the gunicorn.workers.SUPPORTED_WORKERS dictionary
Fixes #1011.
2015-04-22 16:41:45 +03:00
wong2
81f65c2858 extract to a method 2015-03-18 19:18:15 +08:00
wong2
1f8d3b6c37 use self.cfg.reload 2015-03-18 18:52:54 +08:00
wong2
d03891a470 reloader should survive SyntaxError 2015-03-11 20:46:44 +08:00
Randall Leeds
3bb4de4dff Actually expose the reloader
The reloader was not actually being stored on the worker.
2015-03-06 03:04:18 -08:00
Benoit Chesneau
e5f6b8024d add check_config instance method to workers
Add a method to check if config requirements are OK for a specific worker by
adding the `check_config` instance method. This method takes 2 arguments: the
config instance followed by the logger instance to log.

This method is right now used in the thread worker to display a warning in
the case it can't handle keep alive connections. This change is related to #979.
2015-03-06 10:01:31 +01:00
Benoit Chesneau
a459986cfd like in threaded workers let some time to the vm to release locks
applied similar change to 8936d8274770bec5fced09b28eb687b23bef20c1

fix #981
2015-03-06 08:51:14 +01:00