Skip to content

Commit

Permalink
fix possible panic
Browse files Browse the repository at this point in the history
  • Loading branch information
NyaaaWhatsUpDoc committed Jan 19, 2024
1 parent 20dad2f commit 4c6dee1
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions internal/federation/dereferencing/announce.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,19 +107,21 @@ func (d *Dereferencer) EnrichAnnounce(
// All good baby.

case errors.Is(err, db.ErrAlreadyExists):
uri := boost.URI

// DATA RACE! We likely lost out to another goroutine
// in a call to db.Put(Status). Look again in DB by URI.
boost, err = d.state.DB.GetStatusByURI(ctx, boost.URI)
boost, err = d.state.DB.GetStatusByURI(ctx, uri)
if err != nil {
err = gtserror.Newf(
return nil, gtserror.Newf(
"error getting boost wrapper status %s from database after race: %w",
boost.URI, err,
uri, err,
)
}

default:
// Proper database error.
err = gtserror.Newf("db error inserting status: %w", err)
return nil, gtserror.Newf("db error inserting status: %w", err)
}

return boost, err
Expand Down

0 comments on commit 4c6dee1

Please sign in to comment.