mirror of
https://github.com/frappe/gunicorn.git
synced 2026-01-14 11:09:11 +08:00
make sure we don't prematuraly close the fd of the worker tmp file.
fix #407
This commit is contained in:
parent
8cdb4980c8
commit
77251d9d30
8
NOTICE
8
NOTICE
@ -18,7 +18,7 @@ supporting documentation, and that the name of Vinay Sajip
|
|||||||
not be used in advertising or publicity pertaining to distribution
|
not be used in advertising or publicity pertaining to distribution
|
||||||
of the software without specific, written prior permission.
|
of the software without specific, written prior permission.
|
||||||
|
|
||||||
VINAY SAJIP DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
|
VINAY SAJIP DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
|
||||||
INCLUDINGALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
|
INCLUDINGALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
|
||||||
VINAY SAJIP BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
|
VINAY SAJIP BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
|
||||||
ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
|
ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
|
||||||
@ -88,3 +88,9 @@ DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|||||||
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
|
||||||
|
|
||||||
|
util/unlink.py
|
||||||
|
--------------
|
||||||
|
|
||||||
|
backport frop python3 Lib/test/support.py
|
||||||
|
|||||||
@ -159,6 +159,54 @@ def chown(path, uid, gid):
|
|||||||
os.chown(path, uid, -ctypes.c_int(-gid).value)
|
os.chown(path, uid, -ctypes.c_int(-gid).value)
|
||||||
|
|
||||||
|
|
||||||
|
if sys.platform.startswith("win"):
|
||||||
|
def _waitfor(func, pathname, waitall=False):
|
||||||
|
# Peform the operation
|
||||||
|
func(pathname)
|
||||||
|
# Now setup the wait loop
|
||||||
|
if waitall:
|
||||||
|
dirname = pathname
|
||||||
|
else:
|
||||||
|
dirname, name = os.path.split(pathname)
|
||||||
|
dirname = dirname or '.'
|
||||||
|
# Check for `pathname` to be removed from the filesystem.
|
||||||
|
# The exponential backoff of the timeout amounts to a total
|
||||||
|
# of ~1 second after which the deletion is probably an error
|
||||||
|
# anyway.
|
||||||
|
# Testing on a i7@4.3GHz shows that usually only 1 iteration is
|
||||||
|
# required when contention occurs.
|
||||||
|
timeout = 0.001
|
||||||
|
while timeout < 1.0:
|
||||||
|
# Note we are only testing for the existance of the file(s) in
|
||||||
|
# the contents of the directory regardless of any security or
|
||||||
|
# access rights. If we have made it this far, we have sufficient
|
||||||
|
# permissions to do that much using Python's equivalent of the
|
||||||
|
# Windows API FindFirstFile.
|
||||||
|
# Other Windows APIs can fail or give incorrect results when
|
||||||
|
# dealing with files that are pending deletion.
|
||||||
|
L = os.listdir(dirname)
|
||||||
|
if not (L if waitall else name in L):
|
||||||
|
return
|
||||||
|
# Increase the timeout and try again
|
||||||
|
time.sleep(timeout)
|
||||||
|
timeout *= 2
|
||||||
|
warnings.warn('tests may fail, delete still pending for ' + pathname,
|
||||||
|
RuntimeWarning, stacklevel=4)
|
||||||
|
|
||||||
|
def _unlink(filename):
|
||||||
|
_waitfor(os.unlink, filename)
|
||||||
|
else:
|
||||||
|
_unlink = os.unlink
|
||||||
|
|
||||||
|
def unlink(filename):
|
||||||
|
try:
|
||||||
|
_unlink(filename)
|
||||||
|
except OSError as error:
|
||||||
|
# The filename need not exist.
|
||||||
|
if error.errno not in (errno.ENOENT, errno.ENOTDIR):
|
||||||
|
raise
|
||||||
|
|
||||||
|
|
||||||
def is_ipv6(addr):
|
def is_ipv6(addr):
|
||||||
try:
|
try:
|
||||||
socket.inet_pton(socket.AF_INET6, addr)
|
socket.inet_pton(socket.AF_INET6, addr)
|
||||||
|
|||||||
@ -20,7 +20,7 @@ class WorkerTmp(object):
|
|||||||
|
|
||||||
# unlink the file so we don't leak tempory files
|
# unlink the file so we don't leak tempory files
|
||||||
try:
|
try:
|
||||||
os.unlink(name)
|
util.unlink(name)
|
||||||
self._tmp = os.fdopen(fd, 'w+b', 1)
|
self._tmp = os.fdopen(fd, 'w+b', 1)
|
||||||
except:
|
except:
|
||||||
os.close(fd)
|
os.close(fd)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user