forked frompostgres/postgres
- Notifications
You must be signed in to change notification settings - Fork0
Commit664ac3d
committed
Avoid buffer bloat in libpq when server is consistently faster than client.
If the server sends a long stream of data, and the server + network areconsistently fast enough to force the recv() loop in pqReadData() toiterate until libpq's input buffer is full, then upon processing the lastincomplete message in each bufferload we'd usually double the buffer size,due to supposing that we didn't have enough room in the buffer to finishcollecting that message. After filling the newly-enlarged buffer, thecycle repeats, eventually resulting in an out-of-memory situation (whichwould be reported misleadingly as "lost synchronization with server").Of course, we should not enlarge the buffer unless we still need roomafter discarding already-processed messages.This bug dates back quite a long time: pqParseInput3 has had the behaviorsince perhaps 2003, getCopyDataMessage at least since commit70066ebin 2008. Probably the reason it's not been isolated before is that incommon environments the recv() loop would always be faster than the server(if on the same machine) or faster than the network (if not); or at leastit wouldn't be slower consistently enough to let the buffer ramp up to aproblematic size. The reported cases involve Windows, which perhaps hasdifferent timing behavior than other platforms.Per bug #7914 from Shin-ichi Morita, though this is different from hisproposed solution. Back-patch to all supported branches.1 parent2a527ba commit664ac3d
1 file changed
+32
-0
lines changedLines changed: 32 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
318 | 318 |
| |
319 | 319 |
| |
320 | 320 |
| |
| 321 | + | |
321 | 322 |
| |
322 | 323 |
| |
323 | 324 |
| |
| |||
381 | 382 |
| |
382 | 383 |
| |
383 | 384 |
| |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
384 | 416 |
| |
385 | 417 |
| |
386 | 418 |
| |
|
0 commit comments
Comments
(0)