Commit b731683
authored
fix(preprod): Prevent duplicate snapshot PR comments under fanout (#117467)
Re-derive the existing snapshot PR comment id under a
`select_for_update` lock that spans the GitHub call, so concurrent post
tasks for the same PR serialize and update the shared comment in place
instead of each creating its own.
Previously `post_snapshot_pr_comment_task` made the GitHub create/update
call with no lock, deciding create-vs-update from a comment id captured
earlier by `create_preprod_snapshot_pr_comment_task`. A snapshot PR
comment is a single PR-wide table with one row per artifact, so when
several artifacts on a commit finished near-simultaneously, each post
task saw no existing comment and created its own top-level comment. The
result was duplicate comments on the PR, one of which became a
permanently orphaned, never-updated copy once the surviving comment id
was persisted.
The fix moves the existing-comment-id resolution and the GitHub call
inside one transaction holding `select_for_update` locks on every
`CommitComparison` row for the PR. The first poster creates and persists
the comment id; later posters block on the lock, observe the persisted
id, and update. This mirrors the existing build-distribution path
(`create_preprod_pr_comment_task`), which already posts inside the lock.
The shared lock-and-resolve logic is extracted into
`lock_pr_comparisons_for_update`.
Holding the GitHub call inside the lock is deliberate: releasing the
lock before the call would reintroduce the race (two posters both
reading "no comment"). Lock hold time is bounded by the integration
client timeout (30s), which matches the task's processing deadline.
Areas worth careful review:
- The lock now spans a network round-trip to GitHub. This is required
for correctness and consistent with the build-distribution sibling, but
reviewers should confirm they're comfortable with the bounded lock-held
I/O.
- `existing_comment_id` is removed from
`post_snapshot_pr_comment_task`'s signature; in-flight queued messages
that still pass it are absorbed by `**kwargs` during deploy.1 parent fcc6311 commit b731683
3 files changed
Lines changed: 190 additions & 226 deletions
File tree
- src/sentry/preprod/vcs/pr_comments
- tests/sentry/preprod/vcs/pr_comments
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
19 | 19 | | |
20 | 20 | | |
21 | 21 | | |
22 | | - | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
23 | 26 | | |
24 | 27 | | |
25 | 28 | | |
| |||
113 | 116 | | |
114 | 117 | | |
115 | 118 | | |
116 | | - | |
117 | | - | |
118 | | - | |
119 | | - | |
120 | | - | |
121 | | - | |
122 | | - | |
123 | | - | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
124 | 125 | | |
125 | 126 | | |
126 | | - | |
127 | | - | |
128 | | - | |
129 | | - | |
130 | | - | |
131 | | - | |
132 | | - | |
133 | 127 | | |
134 | 128 | | |
135 | 129 | | |
| |||
165 | 159 | | |
166 | 160 | | |
167 | 161 | | |
168 | | - | |
169 | 162 | | |
170 | 163 | | |
171 | 164 | | |
| |||
241 | 234 | | |
242 | 235 | | |
243 | 236 | | |
244 | | - | |
245 | 237 | | |
246 | 238 | | |
247 | 239 | | |
| |||
261 | 253 | | |
262 | 254 | | |
263 | 255 | | |
264 | | - | |
265 | 256 | | |
266 | 257 | | |
267 | 258 | | |
| |||
283 | 274 | | |
284 | 275 | | |
285 | 276 | | |
| 277 | + | |
286 | 278 | | |
287 | 279 | | |
288 | | - | |
289 | | - | |
290 | | - | |
291 | | - | |
292 | | - | |
293 | | - | |
294 | | - | |
295 | | - | |
296 | | - | |
297 | | - | |
298 | | - | |
299 | | - | |
300 | | - | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
301 | 295 | | |
302 | | - | |
303 | | - | |
304 | | - | |
305 | | - | |
306 | | - | |
307 | | - | |
308 | | - | |
309 | | - | |
310 | | - | |
311 | | - | |
312 | | - | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
313 | 323 | | |
314 | | - | |
315 | | - | |
316 | | - | |
317 | | - | |
318 | 324 | | |
319 | 325 | | |
320 | 326 | | |
| |||
328 | 334 | | |
329 | 335 | | |
330 | 336 | | |
331 | | - | |
| 337 | + | |
332 | 338 | | |
333 | 339 | | |
334 | 340 | | |
| |||
338 | 344 | | |
339 | 345 | | |
340 | 346 | | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
341 | 350 | | |
342 | 351 | | |
343 | 352 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
194 | 194 | | |
195 | 195 | | |
196 | 196 | | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
197 | 230 | | |
198 | 231 | | |
199 | 232 | | |
| |||
0 commit comments