Capture os.sendfile before patching in gevent and eventlet workers.

Fixes #1925 and fixes #2170.
This commit is contained in:
Jason Madden 2019-11-13 07:08:26 -06:00
parent 438371ee90
commit 902d9c89ab
No known key found for this signature in database
GPG Key ID: 349F84431A08B99E
2 changed files with 4 additions and 4 deletions

View File

@ -26,10 +26,10 @@ import greenlet
from gunicorn.workers.base_async import AsyncWorker
def _eventlet_sendfile(fdout, fdin, offset, nbytes):
def _eventlet_sendfile(fdout, fdin, offset, nbytes, _os_sendfile=os.sendfile):
while True:
try:
return os.sendfile(fdout, fdin, offset, nbytes)
return _os_sendfile(fdout, fdin, offset, nbytes)
except OSError as e:
if e.args[0] == errno.EAGAIN:
trampoline(fdout, write=True)

View File

@ -30,10 +30,10 @@ from gunicorn.workers.base_async import AsyncWorker
VERSION = "gevent/%s gunicorn/%s" % (gevent.__version__, gunicorn.__version__)
def _gevent_sendfile(fdout, fdin, offset, nbytes):
def _gevent_sendfile(fdout, fdin, offset, nbytes, _os_sendfile=os.sendfile):
while True:
try:
return os.sendfile(fdout, fdin, offset, nbytes)
return _os_sendfile(fdout, fdin, offset, nbytes)
except OSError as e:
if e.args[0] == errno.EAGAIN:
socket.wait_write(fdout)