forked frompostgres/postgres
- Notifications
You must be signed in to change notification settings - Fork6
Commit6b18b3f
committed
Fail hard on out-of-memory failures in xlogreader.c
This commit changes the WAL reader routines so as a FATAL for thebackend or exit(FAILURE) for the frontend is triggered if an allocationfor a WAL record decode fails in walreader.c, rather than treating thiscase as bogus data, which would be equivalent to the end of WAL. Thekey is to avoid palloc_extended(MCXT_ALLOC_NO_OOM) in walreader.c,relying on plain palloc() calls.The previous behavior could make WAL replay finish too early than itshould. For example, crash recovery finishing earlier may corruptclusters because not all the WAL available locally was replayed toensure a consistent state. Out-of-memory failures would show uprandomly depending on the memory pressure on the host, but one simplecase would be to generate a large record, then replay this record afterdownsizing a host, as Ethan Mertz originally reported.This relies onbae868c, as the WAL reader routines now do thememory allocation required for a record only once its header has beenfully read and validated, making xl_tot_len trustable. Making the WALreader react differently on out-of-memory or bogus record data wouldrequire ABI changes, so this is the safest choice for stable branches.Also, it is worth noting that3f1ce97 has been using a plainpalloc() in this code for some time now.Thanks to Noah Misch and Thomas Munro for the discussion.Like the other commit, backpatch down to 12, leaving out v11 that willbe EOL'd soon. The behavior of considering a failed allocation as bogusdata comes originally from0ffe11a, where the record lengthretrieved from its header was not entirely trustable.Reported-by: Ethan MertzDiscussion:https://postgr.es/m/ZRKKdI5-RRlta3aF@paquier.xyzBackpatch-through: 121 parent6c77bb4 commit6b18b3f
1 file changed
+8
-39
lines changedLines changed: 8 additions & 39 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
43 | 43 |
| |
44 | 44 |
| |
45 | 45 |
| |
46 |
| - | |
| 46 | + | |
47 | 47 |
| |
48 | 48 |
| |
49 | 49 |
| |
| |||
155 | 155 |
| |
156 | 156 |
| |
157 | 157 |
| |
158 |
| - | |
159 |
| - | |
160 |
| - | |
161 |
| - | |
162 |
| - | |
163 |
| - | |
164 |
| - | |
165 |
| - | |
| 158 | + | |
166 | 159 |
| |
167 | 160 |
| |
168 | 161 |
| |
| |||
184 | 177 |
| |
185 | 178 |
| |
186 | 179 |
| |
187 |
| - | |
188 | 180 |
| |
189 | 181 |
| |
190 | 182 |
| |
| |||
196 | 188 |
| |
197 | 189 |
| |
198 | 190 |
| |
199 |
| - | |
| 191 | + | |
200 | 192 |
| |
201 | 193 |
| |
202 | 194 |
| |
| |||
206 | 198 |
| |
207 | 199 |
| |
208 | 200 |
| |
209 |
| - | |
210 |
| - | |
211 |
| - | |
212 |
| - | |
213 |
| - | |
214 |
| - | |
215 |
| - | |
| 201 | + | |
216 | 202 |
| |
217 |
| - | |
218 | 203 |
| |
219 | 204 |
| |
220 | 205 |
| |
| |||
505 | 490 |
| |
506 | 491 |
| |
507 | 492 |
| |
508 |
| - | |
509 |
| - | |
510 |
| - | |
| 493 | + | |
511 | 494 |
| |
512 | 495 |
| |
513 | 496 |
| |
| |||
815 | 798 |
| |
816 | 799 |
| |
817 | 800 |
| |
818 |
| - | |
819 |
| - | |
820 |
| - | |
821 |
| - | |
822 |
| - | |
823 |
| - | |
824 |
| - | |
| 801 | + | |
825 | 802 |
| |
826 | 803 |
| |
827 | 804 |
| |
| |||
877 | 854 |
| |
878 | 855 |
| |
879 | 856 |
| |
880 |
| - | |
881 |
| - | |
882 |
| - | |
883 |
| - | |
884 |
| - | |
885 |
| - | |
886 |
| - | |
887 |
| - | |
888 |
| - | |
889 |
| - | |
| 857 | + | |
| 858 | + | |
890 | 859 |
| |
891 | 860 |
| |
892 | 861 |
| |
|
0 commit comments
Comments
(0)