forked frompostgres/postgres
- Notifications
You must be signed in to change notification settings - Fork6
Commitfa4440f
committed
Improve libpq's error recovery for connection loss during COPY.
In pqSendSome, if the connection is already closed at entry, discard anyqueued output data before returning. There is no possibility of eversending the data, and anyway this corresponds to what we'd do if we'ddetected a hard error while trying to send(). This avoids possibleindefinite bloat of the output buffer if the application keeps tryingto send data (or even just keeps trying to do PQputCopyEnd, as psqlindeed will).Because PQputCopyEnd won't transition out of PGASYNC_COPY_IN stateuntil it's successfully queued the COPY END message, and pqPutMsgEnddoesn't distinguish a queuing failure from a pqSendSome failure,this omission allowed an infinite loop in psql if the connection closureoccurred when we had at least 8K queued to send. It might be worthrefactoring so that we can make that distinction, but for the momentthe other changes made here seem to offer adequate defenses.To guard against other variants of this scenario, do not allowPQgetResult to return a PGRES_COPY_XXX result if the connection isalready known dead. Make sure it returns PGRES_FATAL_ERROR instead.Per report from Stephen Frost. Back-patch to all active branches.1 parent993c396 commitfa4440f
2 files changed
+36
-12
lines changedLines changed: 34 additions & 12 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
63 | 63 |
| |
64 | 64 |
| |
65 | 65 |
| |
| 66 | + | |
66 | 67 |
| |
67 | 68 |
| |
68 | 69 |
| |
| |||
1734 | 1735 |
| |
1735 | 1736 |
| |
1736 | 1737 |
| |
1737 |
| - | |
1738 |
| - | |
1739 |
| - | |
1740 |
| - | |
| 1738 | + | |
1741 | 1739 |
| |
1742 | 1740 |
| |
1743 |
| - | |
1744 |
| - | |
1745 |
| - | |
1746 |
| - | |
| 1741 | + | |
1747 | 1742 |
| |
1748 | 1743 |
| |
1749 |
| - | |
1750 |
| - | |
1751 |
| - | |
1752 |
| - | |
| 1744 | + | |
1753 | 1745 |
| |
1754 | 1746 |
| |
1755 | 1747 |
| |
| |||
1786 | 1778 |
| |
1787 | 1779 |
| |
1788 | 1780 |
| |
| 1781 | + | |
| 1782 | + | |
| 1783 | + | |
| 1784 | + | |
| 1785 | + | |
| 1786 | + | |
| 1787 | + | |
| 1788 | + | |
| 1789 | + | |
| 1790 | + | |
| 1791 | + | |
| 1792 | + | |
| 1793 | + | |
| 1794 | + | |
| 1795 | + | |
| 1796 | + | |
| 1797 | + | |
| 1798 | + | |
| 1799 | + | |
| 1800 | + | |
| 1801 | + | |
| 1802 | + | |
| 1803 | + | |
| 1804 | + | |
| 1805 | + | |
| 1806 | + | |
| 1807 | + | |
| 1808 | + | |
| 1809 | + | |
| 1810 | + | |
1789 | 1811 |
| |
1790 | 1812 |
| |
1791 | 1813 |
| |
|
Lines changed: 2 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
804 | 804 |
| |
805 | 805 |
| |
806 | 806 |
| |
| 807 | + | |
| 808 | + | |
807 | 809 |
| |
808 | 810 |
| |
809 | 811 |
| |
|
0 commit comments
Comments
(0)