Skip to content

Commit

Permalink
feat: retry crdb serializable errors
Browse files Browse the repository at this point in the history
  • Loading branch information
aeneasr committed Dec 4, 2024
1 parent 5caa629 commit 4c13d5f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
4 changes: 3 additions & 1 deletion oauth2/oauth2_refresh_token_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,10 @@ func TestCreateRefreshTokenSessionStress(t *testing.T) {
"RETRY_WRITE_TOO_OLD",
// refresh token reuse detection
"token_inactive",
// Failed to refresh token because of multiple concurrent requests using the same token which is not allowed.
"multiple concurrent requests",
} {
if strings.Contains(e.DebugField, errSubstr) {
if strings.Contains(e.DebugField+e.HintField, errSubstr) {
matched = true
break
}
Expand Down
8 changes: 4 additions & 4 deletions persistence/sql/persister_oauth2.go
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ func (p *Persister) createSession(ctx context.Context, signature string, request
}

if err = sqlcon.HandleError(p.CreateWithNetwork(ctx, req)); errors.Is(err, sqlcon.ErrConcurrentUpdate) {
return errors.Wrap(fosite.ErrSerializationFailure, err.Error())
return fosite.ErrSerializationFailure.WithWrap(err)
} else if err != nil {
return err
}
Expand Down Expand Up @@ -293,7 +293,7 @@ func (p *Persister) deleteSessionBySignature(ctx context.Context, signature stri
return errorsx.WithStack(fosite.ErrNotFound)
}
if errors.Is(err, sqlcon.ErrConcurrentUpdate) {
return errors.Wrap(fosite.ErrSerializationFailure, err.Error())
return fosite.ErrSerializationFailure.WithWrap(err)
}
return err
}
Expand All @@ -310,7 +310,7 @@ func (p *Persister) deleteSessionByRequestID(ctx context.Context, id string, tab
}
if err := sqlcon.HandleError(err); err != nil {
if errors.Is(err, sqlcon.ErrConcurrentUpdate) {
return errors.Wrap(fosite.ErrSerializationFailure, err.Error())
return fosite.ErrSerializationFailure.WithWrap(err)
}
if strings.Contains(err.Error(), "Error 1213") { // InnoDB Deadlock?
return errors.Wrap(fosite.ErrSerializationFailure, err.Error())
Expand Down Expand Up @@ -426,7 +426,7 @@ func (p *Persister) DeleteAccessTokenSession(ctx context.Context, signature stri
}
}
if errors.Is(err, sqlcon.ErrConcurrentUpdate) {
return errors.Wrap(fosite.ErrSerializationFailure, err.Error())
return fosite.ErrSerializationFailure.WithWrap(err)
}
return err
}
Expand Down

0 comments on commit 4c13d5f

Please sign in to comment.