- Notifications
You must be signed in to change notification settings - Fork5.2k
Commitf6f0542
libpq: Handle OOM by disconnecting instead of hanging or skipping msgs
In most cases, if an out-of-memory situation happens, we attach theerror message to the connection and report it at the nextPQgetResult() call. However, there are a few cases, while processingmessages that are not associated with any particular query, where wehandled failed allocations differently and not very nicely:- If we ran out of memory while processing an async notification, getNotify() either returned EOF, which stopped processing any further data until more data was received from the server, or silently dropped the notification. Returning EOF is problematic because if more data never arrives, e.g. because the connection was used just to wait for the notification, or because the next ReadyForQuery was already received and buffered, it would get stuck forever. Silently dropping a notification is not nice either.- (New in v18) If we ran out of memory while receiving BackendKeyData message, getBackendKeyData() returned EOF, which has the same issues as in getNotify().- If we ran out of memory while saving a received a ParameterStatus message, we just skipped it. A later call to PQparameterStatus() would return NULL, even though the server did send the status.Change all those cases to terminate the connnection instead. Ouroptions for reporting those errors are limited, but it seems better toterminate than try to soldier on. Applications should handleconnection loss gracefully, whereas silently missing a notification,parameter status, or cancellation key could cause much weirderproblems.This also changes the error message on OOM while expanding the inputbuffer. It used to report "cannot allocate memory for input buffer",followed by "lost synchronization with server: got message type ...".The "lost synchronization" message seems unnecessary, so remove thatand report only "cannot allocate memory for input buffer". (Thecomment speculated that the out of memory could indeed be caused byloss of sync, but that seems highly unlikely.)This evolved from a more narrow patch by Jelte Fennema-Nio, which wasreviewed by Jacob Champion.Somewhat arbitrarily, backpatch to v18 but no further. These arelong-standing issues, but we haven't received any complaints from thefield. We can backpatch more later, if needed.Co-authored-by: Jelte Fennema-Nio <postgres@jeltef.nl>Reviewed-by: Jelte Fennema-Nio <postgres@jeltef.nl>Reviewed-by: Jacob Champion <jchampion@postgresql.org>Discussion:https://www.postgresql.org/message-id/df892f9f-5923-4046-9d6f-8c48d8980b50@iki.fiBackpatch-through: 181 parent661f821 commitf6f0542
3 files changed
+89
-40
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1076 | 1076 | | |
1077 | 1077 | | |
1078 | 1078 | | |
| 1079 | + | |
| 1080 | + | |
| 1081 | + | |
| 1082 | + | |
1079 | 1083 | | |
1080 | | - | |
| 1084 | + | |
1081 | 1085 | | |
1082 | 1086 | | |
1083 | 1087 | | |
| |||
1119 | 1123 | | |
1120 | 1124 | | |
1121 | 1125 | | |
| 1126 | + | |
| 1127 | + | |
| 1128 | + | |
| 1129 | + | |
| 1130 | + | |
1122 | 1131 | | |
1123 | 1132 | | |
1124 | 1133 | | |
| |||
1190 | 1199 | | |
1191 | 1200 | | |
1192 | 1201 | | |
| 1202 | + | |
| 1203 | + | |
1193 | 1204 | | |
1194 | 1205 | | |
1195 | 1206 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
43 | 43 | | |
44 | 44 | | |
45 | 45 | | |
| 46 | + | |
46 | 47 | | |
47 | 48 | | |
48 | 49 | | |
| |||
120 | 121 | | |
121 | 122 | | |
122 | 123 | | |
123 | | - | |
124 | | - | |
125 | | - | |
126 | | - | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
127 | 128 | | |
128 | | - | |
| 129 | + | |
129 | 130 | | |
130 | 131 | | |
131 | 132 | | |
| |||
456 | 457 | | |
457 | 458 | | |
458 | 459 | | |
| 460 | + | |
| 461 | + | |
| 462 | + | |
| 463 | + | |
| 464 | + | |
459 | 465 | | |
460 | 466 | | |
461 | 467 | | |
| |||
470 | 476 | | |
471 | 477 | | |
472 | 478 | | |
473 | | - | |
| 479 | + | |
474 | 480 | | |
475 | | - | |
| 481 | + | |
| 482 | + | |
476 | 483 | | |
477 | 484 | | |
478 | | - | |
| 485 | + | |
479 | 486 | | |
480 | | - | |
481 | | - | |
482 | 487 | | |
483 | 488 | | |
484 | 489 | | |
| |||
487 | 492 | | |
488 | 493 | | |
489 | 494 | | |
| 495 | + | |
| 496 | + | |
| 497 | + | |
| 498 | + | |
| 499 | + | |
| 500 | + | |
| 501 | + | |
| 502 | + | |
| 503 | + | |
| 504 | + | |
| 505 | + | |
| 506 | + | |
| 507 | + | |
490 | 508 | | |
491 | 509 | | |
492 | 510 | | |
| |||
1519 | 1537 | | |
1520 | 1538 | | |
1521 | 1539 | | |
1522 | | - | |
| 1540 | + | |
| 1541 | + | |
| 1542 | + | |
| 1543 | + | |
| 1544 | + | |
1523 | 1545 | | |
1524 | 1546 | | |
1525 | 1547 | | |
| |||
1551 | 1573 | | |
1552 | 1574 | | |
1553 | 1575 | | |
1554 | | - | |
1555 | | - | |
| 1576 | + | |
| 1577 | + | |
1556 | 1578 | | |
1557 | 1579 | | |
1558 | 1580 | | |
| |||
1589 | 1611 | | |
1590 | 1612 | | |
1591 | 1613 | | |
1592 | | - | |
| 1614 | + | |
| 1615 | + | |
| 1616 | + | |
| 1617 | + | |
| 1618 | + | |
| 1619 | + | |
| 1620 | + | |
| 1621 | + | |
| 1622 | + | |
| 1623 | + | |
| 1624 | + | |
1593 | 1625 | | |
1594 | 1626 | | |
1595 | | - | |
| 1627 | + | |
| 1628 | + | |
1596 | 1629 | | |
1597 | 1630 | | |
1598 | 1631 | | |
| |||
1604 | 1637 | | |
1605 | 1638 | | |
1606 | 1639 | | |
1607 | | - | |
1608 | | - | |
1609 | | - | |
1610 | | - | |
1611 | | - | |
1612 | | - | |
1613 | | - | |
1614 | | - | |
1615 | | - | |
1616 | | - | |
1617 | | - | |
1618 | | - | |
1619 | | - | |
| 1640 | + | |
| 1641 | + | |
| 1642 | + | |
| 1643 | + | |
| 1644 | + | |
| 1645 | + | |
1620 | 1646 | | |
1621 | 1647 | | |
| 1648 | + | |
| 1649 | + | |
| 1650 | + | |
| 1651 | + | |
| 1652 | + | |
| 1653 | + | |
| 1654 | + | |
| 1655 | + | |
| 1656 | + | |
| 1657 | + | |
| 1658 | + | |
| 1659 | + | |
1622 | 1660 | | |
1623 | 1661 | | |
1624 | 1662 | | |
| |||
1752 | 1790 | | |
1753 | 1791 | | |
1754 | 1792 | | |
1755 | | - | |
1756 | | - | |
1757 | | - | |
1758 | | - | |
| 1793 | + | |
| 1794 | + | |
| 1795 | + | |
| 1796 | + | |
1759 | 1797 | | |
1760 | | - | |
| 1798 | + | |
1761 | 1799 | | |
1762 | 1800 | | |
1763 | 1801 | | |
| |||
2186 | 2224 | | |
2187 | 2225 | | |
2188 | 2226 | | |
2189 | | - | |
2190 | | - | |
2191 | | - | |
2192 | | - | |
| 2227 | + | |
| 2228 | + | |
| 2229 | + | |
| 2230 | + | |
2193 | 2231 | | |
2194 | | - | |
| 2232 | + | |
2195 | 2233 | | |
2196 | 2234 | | |
2197 | 2235 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
746 | 746 | | |
747 | 747 | | |
748 | 748 | | |
749 | | - | |
| 749 | + | |
750 | 750 | | |
751 | 751 | | |
752 | 752 | | |
| |||
0 commit comments
Comments
(0)