mirror of
https://github.com/songquanpeng/one-api.git
synced 2025-11-10 02:23:43 +08:00
fix: resolve race condition in processChannelRelayError and update API version handling for gemini-2.0-flash-exp
This commit is contained in:
@@ -58,8 +58,7 @@ func Relay(c *gin.Context) {
|
||||
channelName := c.GetString(ctxkey.ChannelName)
|
||||
group := c.GetString(ctxkey.Group)
|
||||
originalModel := c.GetString(ctxkey.OriginalModel)
|
||||
// BUG: bizErr is shared, should not run this function in goroutine to avoid race
|
||||
go processChannelRelayError(ctx, userId, channelId, channelName, bizErr)
|
||||
go processChannelRelayError(ctx, userId, channelId, channelName, *bizErr)
|
||||
requestId := c.GetString(helper.RequestIdKey)
|
||||
retryTimes := config.RetryTimes
|
||||
if err := shouldRetry(c, bizErr.StatusCode); err != nil {
|
||||
@@ -86,8 +85,7 @@ func Relay(c *gin.Context) {
|
||||
channelId := c.GetInt(ctxkey.ChannelId)
|
||||
lastFailedChannelId = channelId
|
||||
channelName := c.GetString(ctxkey.ChannelName)
|
||||
// BUG: bizErr is in race condition
|
||||
go processChannelRelayError(ctx, userId, channelId, channelName, bizErr)
|
||||
go processChannelRelayError(ctx, userId, channelId, channelName, *bizErr)
|
||||
}
|
||||
|
||||
if bizErr != nil {
|
||||
@@ -119,7 +117,7 @@ func shouldRetry(c *gin.Context, statusCode int) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func processChannelRelayError(ctx context.Context, userId int, channelId int, channelName string, err *model.ErrorWithStatusCode) {
|
||||
func processChannelRelayError(ctx context.Context, userId int, channelId int, channelName string, err model.ErrorWithStatusCode) {
|
||||
logger.Errorf(ctx, "relay error (channel id %d, user id: %d): %s", channelId, userId, err.Message)
|
||||
// https://platform.openai.com/docs/guides/error-codes/api-errors
|
||||
if monitor.ShouldDisableChannel(&err.Error, err.StatusCode) {
|
||||
|
||||
Reference in New Issue
Block a user