-
-
Save coldmind/a45879b0e4941336b24e to your computer and use it in GitHub Desktop.
socket read timeout in django request
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/django/core/handlers/wsgi.py b/django/core/handlers/wsgi.py | |
index 50766cb..b133310 100644 | |
--- a/django/core/handlers/wsgi.py | |
+++ b/django/core/handlers/wsgi.py | |
@@ -38,9 +38,14 @@ class LimitedStream(object): | |
size = self.remaining | |
if size == 0: | |
return b'' | |
- result = self.stream.read(size) | |
- self.remaining -= len(result) | |
- return result | |
+ self.stream._sock.settimeout(10) | |
+ try: | |
+ result = self.stream.read(size) | |
+ except http.UnreadablePostError: | |
+ raise Exception('Some exception') | |
+ else: | |
+ self.remaining -= len(result) | |
+ return result | |
def read(self, size=None): | |
if size is None: |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment