graph/db: gracefully handle duplicate node announcements

It can happen that we are handling 2 of the same node announcements in
the same batch transaction. In that case, our `UpsertNode` conflict
assertion may fail. We need to handle this gracefully.
This commit is contained in:
Elle Mouton committed 2025-10-06 11:28:33 +02:00
1 parent 88050da220
commit abb9654856
2 files changed
+19

No files matched your search

+11
View File
@@ -255,6 +255,17 @@ func (s *SQLStore) AddNode(ctx context.Context,
Opts: batch.NewSchedulerOptions(opts...),
Do: func(queries SQLQueries) error {
_, err := upsertNode(ctx, queries, node)
// It is possible that two of the same node
// announcements are both being processed in the same
// batch. This may case the UpsertNode conflict to
// be hit since we require at the db layer that the
// new last_update is greater than the existing
// last_update. We need to gracefully handle this here.
if errors.Is(err, sql.ErrNoRows) {
return nil
}
return err
},
}