Commit 1b94803
Apply backpressure to inbound HTTP connections
HttpConnectionBase::loop() used to drain the socket unconditionally, so
when data arrived faster than the query parser consumed it (e.g. a big
file upload saved to a slow disk), unbounded amounts of received data
accumulated in memory: uploading a 512 MB file could transiently hold
more than 1 GB in buffers.
Stop reading from the socket while more than MAX_PENDING_READ_SIZE of
received data is pending in memory. The kernel receive buffer then
fills up and TCP flow control throttles the peer, keeping memory usage
constant however large the request is. The same upload now peaks below
8 MB of buffer memory.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>1 parent d8d46df commit 1b94803
2 files changed
Lines changed: 21 additions & 6 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
100 | 100 | | |
101 | 101 | | |
102 | 102 | | |
103 | | - | |
104 | | - | |
105 | | - | |
106 | | - | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
107 | 112 | | |
108 | | - | |
109 | | - | |
110 | 113 | | |
111 | 114 | | |
112 | 115 | | |
| |||
195 | 198 | | |
196 | 199 | | |
197 | 200 | | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
198 | 207 | | |
199 | 208 | | |
200 | 209 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
36 | 36 | | |
37 | 37 | | |
38 | 38 | | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
39 | 45 | | |
40 | 46 | | |
41 | 47 | | |
| |||
0 commit comments