Commit b6e5220
Fix PartitionedOutput crash after flush (#16496)
Summary:
Pull Request resolved: #16496
This change fixes a segmentation fault (SIGSEGV) crash in Prestissimo's PartitionedOutput operator that was causing Presto Batch UER violations.
## Root Cause Analysis
The crash occurred in `Destination::advance()` after `Destination::flush()` was called. After `flush()` calls `current_->clear()`:
1. `VectorStreamGroup::clear()` clears the serializer but the stream tree isn't properly reinitialized
2. On the next `advance()` call, we skip `createStreamTree()` because `current_ != nullptr`
3. We try to append to a serializer that's in an invalid state
4. This causes a SIGSEGV due to stale references to freed StreamArena memory
## The Fix
Added a `needsStreamTreeRecreation_` flag to the Destination class:
- After `flush()`, the flag is set to true
- In `advance()`, when this flag is true, we call `createStreamTree()` to reinitialize the serializer with a fresh stream tree
- This ensures the serializer is properly initialized before any append operations
This approach:
1. Keeps the VectorStreamGroup object alive (avoiding issues with memory lifetime)
2. Forces proper reinitialization of the serializer via `createStreamTree()`
3. Fixes the original crash while maintaining compatibility with all serde types
## Evidence
- Stack traces showed SIGSEGV during `append()` operations after flush
- `VectorStreamGroup::clear()` has a TODO comment: "provide a separate method to initialize the serializer header" - confirming the clear() method has known limitations
- The fix aligns with how the code already handles initial creation (checking null and calling createStreamTree)
Reviewed By: xiaoxmeng
Differential Revision: D94097942
fbshipit-source-id: ebc114f58a084e0dc322193b64115539420ab5a31 parent 8693d33 commit b6e5220
File tree
4 files changed
+142
-14
lines changed- velox/exec
- tests
4 files changed
+142
-14
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
76 | 76 | | |
77 | 77 | | |
78 | 78 | | |
79 | | - | |
80 | | - | |
81 | | - | |
82 | | - | |
83 | | - | |
| 79 | + | |
84 | 80 | | |
85 | 81 | | |
86 | 82 | | |
| |||
104 | 100 | | |
105 | 101 | | |
106 | 102 | | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
107 | 123 | | |
108 | 124 | | |
109 | 125 | | |
| |||
122 | 138 | | |
123 | 139 | | |
124 | 140 | | |
125 | | - | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
126 | 155 | | |
127 | 156 | | |
128 | 157 | | |
| |||
145 | 174 | | |
146 | 175 | | |
147 | 176 | | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
148 | 185 | | |
149 | 186 | | |
150 | | - | |
151 | | - | |
152 | | - | |
| 187 | + | |
| 188 | + | |
153 | 189 | | |
154 | 190 | | |
155 | 191 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
102 | 102 | | |
103 | 103 | | |
104 | 104 | | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
105 | 114 | | |
106 | 115 | | |
107 | 116 | | |
| |||
122 | 131 | | |
123 | 132 | | |
124 | 133 | | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
125 | 144 | | |
126 | 145 | | |
127 | 146 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3090 | 3090 | | |
3091 | 3091 | | |
3092 | 3092 | | |
3093 | | - | |
3094 | | - | |
3095 | | - | |
3096 | | - | |
3097 | | - | |
| 3093 | + | |
| 3094 | + | |
| 3095 | + | |
| 3096 | + | |
| 3097 | + | |
| 3098 | + | |
| 3099 | + | |
| 3100 | + | |
3098 | 3101 | | |
3099 | 3102 | | |
3100 | 3103 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
206 | 206 | | |
207 | 207 | | |
208 | 208 | | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
209 | 279 | | |
210 | 280 | | |
211 | 281 | | |
| |||
0 commit comments