diff options
author | Andrey Kosyakov <caseq@chromium.org> | 2015-03-25 05:45:49 -0700 |
---|---|---|
committer | Andrey Kosyakov <caseq@chromium.org> | 2015-03-25 08:30:22 -0700 |
commit | dc40b7bedaaa2df27ac633bfcf51a79f1b6fa1d4 (patch) | |
tree | ee35aae3f1ee305a665fcfa6e596cd63bf2d70b7 /websocket | |
parent | 5d04ab5bae60181601f44b368fd37bdeffb918e3 (diff) | |
download | websocket-client-dc40b7bedaaa2df27ac633bfcf51a79f1b6fa1d4.tar.gz |
Fix out-of-memory due to fragmentation when recieving a very large frame
Diffstat (limited to 'websocket')
-rw-r--r-- | websocket/_abnf.py | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/websocket/_abnf.py b/websocket/_abnf.py index d97cfdd..6bf39b4 100644 --- a/websocket/_abnf.py +++ b/websocket/_abnf.py @@ -323,7 +323,12 @@ class frame_buffer(object): def recv_strict(self, bufsize): shortage = bufsize - sum(len(x) for x in self.recv_buffer) while shortage > 0: - bytes = self.recv(shortage) + # Limit buffer size that we pass to socket.recv() to avoid + # fragmenting the heap -- the number of bytes recv() actually + # reads is limited by socket buffer and is relatively small, + # yet passing large numbers repeatedly causes lots of large + # buffers allocated and then shrunk, which results in fragmentation. + bytes = self.recv(min(16384, shortage)) self.recv_buffer.append(bytes) shortage -= len(bytes) |