fix databroker restart versioning, handle missing sessions (#1145)

* fix databroker restart versioning, handle missing sessions

* send empty server version to detect change

* only rebuild if there are updated records
This commit is contained in:
Caleb Doxsey 2020-07-29 08:45:41 -06:00 committed by GitHub
parent a5e8abd6af
commit 557aef2a33
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 53 additions and 62 deletions

View file

@ -49,19 +49,6 @@ func (a *Authorize) Check(ctx context.Context, in *envoy_service_auth_v2.CheckRe
rawJWT, _ := loadRawSession(hreq, a.currentOptions.Load(), a.currentEncoder.Load())
sessionState, _ := loadSession(a.currentEncoder.Load(), rawJWT)
// only accept sessions whose databroker server versions match
if sessionState != nil {
a.dataBrokerDataLock.RLock()
if a.dataBrokerSessionServerVersion != sessionState.Version.String() {
log.Warn().
Str("server_version", a.dataBrokerSessionServerVersion).
Str("session_version", sessionState.Version.String()).
Msg("clearing session due to invalid version")
sessionState = nil
}
a.dataBrokerDataLock.RUnlock()
}
if err := a.forceSync(ctx, sessionState); err != nil {
log.Warn().Err(err).Msg("clearing session due to force sync failed")
sessionState = nil
@ -98,7 +85,7 @@ func (a *Authorize) forceSync(ctx context.Context, ss *sessions.State) error {
}
s := a.forceSyncSession(ctx, ss.ID)
if s == nil {
return nil
return errors.New("session not found")
}
if s.DeletedAt != nil {
return errors.New("session was deleted")