Remove recursion limit for now and other review fixes

This commit is contained in:
Neil Alexander 2020-03-06 15:55:44 +00:00
parent 20e2c48628
commit bc8abbc51d

View file

@ -17,7 +17,6 @@ package routing
import ( import (
"context" "context"
"encoding/json" "encoding/json"
"errors"
"fmt" "fmt"
"net/http" "net/http"
@ -159,7 +158,7 @@ func (t *txnReq) processEvent(e gomatrixserverlib.Event) error {
} }
if !stateResp.PrevEventsExist { if !stateResp.PrevEventsExist {
return t.processEventWithMissingState(e, 0) return t.processEventWithMissingState(e)
} }
// Check that the event is allowed by the state at the event. // Check that the event is allowed by the state at the event.
@ -186,11 +185,7 @@ func checkAllowedByState(e gomatrixserverlib.Event, stateEvents []gomatrixserver
return gomatrixserverlib.Allowed(e, &authUsingState) return gomatrixserverlib.Allowed(e, &authUsingState)
} }
func (t *txnReq) processEventWithMissingState(e gomatrixserverlib.Event, depth int) error { func (t *txnReq) processEventWithMissingState(e gomatrixserverlib.Event) error {
if depth > 15 {
return errors.New("recursion limit hit trying to process event with missing state")
}
// We are missing the previous events for this events. // We are missing the previous events for this events.
// This means that there is a gap in our view of the history of the // This means that there is a gap in our view of the history of the
// room. There two ways that we can handle such a gap: // room. There two ways that we can handle such a gap:
@ -222,8 +217,10 @@ retryAllowedState:
case gomatrixserverlib.MissingAuthEventError: case gomatrixserverlib.MissingAuthEventError:
// An auth event was missing so let's look up that event over federation // An auth event was missing so let's look up that event over federation
for _, s := range state.StateEvents { for _, s := range state.StateEvents {
if s.EventID() == missing.AuthEventID { if s.EventID() != missing.AuthEventID {
if serr := t.processEventWithMissingState(s, depth+1); serr == nil { continue
}
if serr := t.processEventWithMissingState(s); serr == nil {
// If there was no error retrieving the event from federation then // If there was no error retrieving the event from federation then
// we assume that it succeeded, so retry the original state check // we assume that it succeeded, so retry the original state check
goto retryAllowedState goto retryAllowedState
@ -232,7 +229,6 @@ retryAllowedState:
return err return err
} }
} }
}
default: default:
// Some other error condition happened that wasn't a missing auth event // Some other error condition happened that wasn't a missing auth event
return err return err