Always acquire db lock before calling Owns
このコミットが含まれているのは:
コミット
c4a7b0524e
|
@ -43,9 +43,7 @@ type Database interface {
|
||||||
// Owns returns true if the database has an entry for the IRI and it
|
// Owns returns true if the database has an entry for the IRI and it
|
||||||
// exists in the database.
|
// exists in the database.
|
||||||
//
|
//
|
||||||
// TODO: Acquire a lock
|
// The library makes this call only after acquiring a lock first.
|
||||||
//
|
|
||||||
// Owns is called without acquiring a lock.
|
|
||||||
Owns(c context.Context, id *url.URL) (owns bool, err error)
|
Owns(c context.Context, id *url.URL) (owns bool, err error)
|
||||||
// ActorForOutbox fetches the actor's IRI for the given outbox IRI.
|
// ActorForOutbox fetches the actor's IRI for the given outbox IRI.
|
||||||
//
|
//
|
||||||
|
|
|
@ -175,11 +175,20 @@ func (a *sideEffectActor) InboxForwarding(c context.Context, inboxIRI *url.URL,
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
err = a.db.Lock(c, iri)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
// WARNING: Unlock is not deferred
|
||||||
if owns, err := a.db.Owns(c, iri); err != nil {
|
if owns, err := a.db.Owns(c, iri); err != nil {
|
||||||
|
a.db.Unlock(c, iri)
|
||||||
return err
|
return err
|
||||||
} else if !owns {
|
} else if !owns {
|
||||||
|
a.db.Unlock(c, iri)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
a.db.Unlock(c, iri)
|
||||||
|
// Unlock by this point and in every branch above.
|
||||||
myIRIs = append(myIRIs, iri)
|
myIRIs = append(myIRIs, iri)
|
||||||
}
|
}
|
||||||
// Finally, load our IRIs to determine if they are a Collection or
|
// Finally, load our IRIs to determine if they are a Collection or
|
||||||
|
@ -483,21 +492,41 @@ func (a *sideEffectActor) hasInboxForwardingValues(c context.Context, inboxIRI *
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
|
err = a.db.Lock(c, id)
|
||||||
|
if err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
// WARNING: Unlock is not deferred
|
||||||
if owns, err := a.db.Owns(c, id); err != nil {
|
if owns, err := a.db.Owns(c, id); err != nil {
|
||||||
|
a.db.Unlock(c, id)
|
||||||
return false, err
|
return false, err
|
||||||
} else if owns {
|
} else if owns {
|
||||||
|
a.db.Unlock(c, id)
|
||||||
return true, nil
|
return true, nil
|
||||||
}
|
}
|
||||||
|
a.db.Unlock(c, id)
|
||||||
|
// Unlock by this point and in every branch above
|
||||||
|
//
|
||||||
// Determine if we own the 'id' of any values on the properties we care
|
// Determine if we own the 'id' of any values on the properties we care
|
||||||
// about.
|
// about.
|
||||||
types, iris := getInboxForwardingValues(val)
|
types, iris := getInboxForwardingValues(val)
|
||||||
// For IRIs, simply check if we own them.
|
// For IRIs, simply check if we own them.
|
||||||
for _, iri := range iris {
|
for _, iri := range iris {
|
||||||
|
err = a.db.Lock(c, iri)
|
||||||
|
if err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
// WARNING: Unlock is not deferred
|
||||||
if owns, err := a.db.Owns(c, iri); err != nil {
|
if owns, err := a.db.Owns(c, iri); err != nil {
|
||||||
|
a.db.Unlock(c, iri)
|
||||||
return false, err
|
return false, err
|
||||||
} else if owns {
|
} else if owns {
|
||||||
|
a.db.Unlock(c, iri)
|
||||||
return true, nil
|
return true, nil
|
||||||
}
|
}
|
||||||
|
a.db.Unlock(c, iri)
|
||||||
|
// Unlock by this point and in every branch above
|
||||||
|
//
|
||||||
// Attempt to dereference the IRI instead, and add it to the
|
// Attempt to dereference the IRI instead, and add it to the
|
||||||
// types we need to examine.
|
// types we need to examine.
|
||||||
tport, err := a.common.NewTransport(c, inboxIRI, goFedUserAgent())
|
tport, err := a.common.NewTransport(c, inboxIRI, goFedUserAgent())
|
||||||
|
|
読み込み中…
新しいイシューから参照