#600 avoid conn closing in case of reach the limit

This commit is contained in:
smallnest
2021-12-29 08:53:48 +08:00
parent f4bc55644b
commit 09ea6cd72f
2 changed files with 29 additions and 5 deletions
+2 -4
View File
@@ -2,14 +2,12 @@ package serverplugin
import (
"context"
"errors"
"time"
"github.com/juju/ratelimit"
"github.com/smallnest/rpcx/server"
)
var ErrReqReachLimit = errors.New("request reached rate limit")
// ReqRateLimitingPlugin can limit requests per unit time
type ReqRateLimitingPlugin struct {
FillInterval time.Duration
@@ -41,5 +39,5 @@ func (plugin *ReqRateLimitingPlugin) PreReadRequest(ctx context.Context) error {
if count == 1 {
return nil
}
return ErrReqReachLimit
return server.ErrReqReachLimit
}