mirror of
https://github.com/smallnest/rpcx.git
synced 2026-04-22 23:27:06 +08:00
#600 avoid conn closing in case of reach the limit
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user