- Notifications
You must be signed in to change notification settings - Fork28
Commitffa4cbd
committed
Handle EPIPE more sanely when we close a pipe reading from a program.
Previously, any program launched by COPY TO/FROM PROGRAM inherited theserver's setting of SIGPIPE handling, i.e. SIG_IGN. Hence, if we weredoing COPY FROM PROGRAM and closed the pipe early, the child processwould see EPIPE on its output file and typically would treat that asa fatal error, in turn causing the COPY to report error. Similarly,one could get a failure report from a query that didn't read all ofthe output from a contrib/file_fdw foreign table that uses file_fdw'sPROGRAM option.To fix, ensure that child programs inherit SIG_DFL not SIG_IGN processingof SIGPIPE. This seems like an all-around better situation since ifthe called program wants some non-default treatment of SIGPIPE, it wouldexpect to have to set that up for itself. Then in COPY, if it's COPYFROM PROGRAM and we stop reading short of detecting EOF, treat a SIGPIPEexit from the called program as a non-error condition. This still allowsus to report an error for any case where the called program gets SIGPIPEon some other file descriptor.As coded, we won't report a SIGPIPE if we stop reading as a result ofseeing an in-band EOF marker (e.g. COPY BINARY EOF marker). It'ssomewhat debatable whether we should complain if the called programcontinues to transmit data after an EOF marker. However, it seems likewe should avoid throwing error in any questionable cases, especially in aback-patched fix, and anyway it would take additional code to make suchan error get reported consistently.Back-patch to v10. We could go further back, since COPY FROM PROGRAMhas been around awhile, but AFAICS the only way to reach this situationusing core or contrib is via file_fdw, which has only supported PROGRAMsources since v10. The COPY statement per se has no feature wherebyit'd stop reading without having hit EOF or an error already. Therefore,I don't see any upside to back-patching further that'd outweigh therisk of complaints about behavioral change.Per bug #15449 from Eric Cyr.Patch by me, review by Etsuro Fujita and Kyotaro HoriguchiDiscussion:https://postgr.es/m/15449-1cf737dd5929450e@postgresql.org1 parentd56e0fd commitffa4cbd
2 files changed
+33
-8
lines changedLines changed: 22 additions & 4 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
114 | 114 |
| |
115 | 115 |
| |
116 | 116 |
| |
117 |
| - | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
118 | 120 |
| |
119 | 121 |
| |
120 | 122 |
| |
| |||
575 | 577 |
| |
576 | 578 |
| |
577 | 579 |
| |
| 580 | + | |
| 581 | + | |
578 | 582 |
| |
579 | 583 |
| |
580 | 584 |
| |
| |||
595 | 599 |
| |
596 | 600 |
| |
597 | 601 |
| |
598 |
| - | |
| 602 | + | |
599 | 603 |
| |
600 | 604 |
| |
601 | 605 |
| |
| |||
623 | 627 |
| |
624 | 628 |
| |
625 | 629 |
| |
626 |
| - | |
| 630 | + | |
627 | 631 |
| |
628 | 632 |
| |
629 | 633 |
| |
| |||
1050 | 1054 |
| |
1051 | 1055 |
| |
1052 | 1056 |
| |
| 1057 | + | |
| 1058 | + | |
1053 | 1059 |
| |
1054 | 1060 |
| |
1055 | 1061 |
| |
| |||
1727 | 1733 |
| |
1728 | 1734 |
| |
1729 | 1735 |
| |
| 1736 | + | |
| 1737 | + | |
| 1738 | + | |
| 1739 | + | |
| 1740 | + | |
| 1741 | + | |
| 1742 | + | |
| 1743 | + | |
| 1744 | + | |
| 1745 | + | |
| 1746 | + | |
1730 | 1747 |
| |
1731 | 1748 |
| |
1732 | 1749 |
| |
1733 | 1750 |
| |
1734 | 1751 |
| |
| 1752 | + | |
1735 | 1753 |
| |
1736 | 1754 |
| |
1737 | 1755 |
| |
| |||
3194 | 3212 |
| |
3195 | 3213 |
| |
3196 | 3214 |
| |
3197 |
| - | |
| 3215 | + | |
3198 | 3216 |
| |
3199 | 3217 |
| |
3200 | 3218 |
| |
|
Lines changed: 11 additions & 4 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
2279 | 2279 |
| |
2280 | 2280 |
| |
2281 | 2281 |
| |
| 2282 | + | |
| 2283 | + | |
| 2284 | + | |
| 2285 | + | |
2282 | 2286 |
| |
2283 | 2287 |
| |
2284 | 2288 |
| |
2285 | 2289 |
| |
2286 | 2290 |
| |
| 2291 | + | |
2287 | 2292 |
| |
2288 | 2293 |
| |
2289 | 2294 |
| |
| |||
2301 | 2306 |
| |
2302 | 2307 |
| |
2303 | 2308 |
| |
| 2309 | + | |
2304 | 2310 |
| |
2305 |
| - | |
| 2311 | + | |
| 2312 | + | |
| 2313 | + | |
| 2314 | + | |
| 2315 | + | |
2306 | 2316 |
| |
2307 | 2317 |
| |
2308 | 2318 |
| |
| |||
2315 | 2325 |
| |
2316 | 2326 |
| |
2317 | 2327 |
| |
2318 |
| - | |
2319 |
| - | |
2320 | 2328 |
| |
2321 | 2329 |
| |
2322 | 2330 |
| |
2323 |
| - | |
2324 | 2331 |
| |
2325 | 2332 |
| |
2326 | 2333 |
| |
|
0 commit comments
Comments
(0)