@@ -24,12 +24,14 @@ type Conn interface {
2424
2525 Endpoint () endpoint.Endpoint
2626
27+ TTL () <- chan time.Time
28+
2729 IsState (states ... State ) bool
2830 GetState () State
2931 SetState (State ) State
32+
3033 Close (ctx context.Context ) error
3134 Park (ctx context.Context ) error
32- TTL () <- chan time.Time
3335}
3436
3537func (c * conn ) Address () string {
@@ -38,16 +40,15 @@ func (c *conn) Address() string {
3840
3941type conn struct {
4042 sync.RWMutex
41- config Config // ro access
42- cc * grpc.ClientConn
43- done chan struct {}
44- endpoint endpoint.Endpoint // ro access
45- closed bool
46- state State
47- usages int32
48- ttl timeutil.Timer
49- onClose []func (Conn )
50- onPessimize []func (e endpoint.Endpoint )
43+ config Config // ro access
44+ cc * grpc.ClientConn
45+ done chan struct {}
46+ endpoint endpoint.Endpoint // ro access
47+ closed bool
48+ state State
49+ usages int32
50+ ttl timeutil.Timer
51+ onClose []func (Conn )
5152}
5253
5354func (c * conn ) IsState (states ... State ) bool {
@@ -262,39 +263,13 @@ func (c *conn) Close(ctx context.Context) (err error) {
262263 return err
263264}
264265
265- func (c * conn ) pessimize (ctx context.Context , err error ) {
266- if c .isClosed () {
267- return
268- }
269-
270- defer func () {
271- for _ , f := range c .onPessimize {
272- f (c .endpoint )
273- }
274- }()
275-
276- trace .DriverOnPessimizeNode (
277- trace .ContextDriver (ctx ).Compose (c .config .Trace ()),
278- & ctx ,
279- c .endpoint .Copy (),
280- c .GetState (),
281- err ,
282- )(c .SetState (Banned ))
283- }
284-
285266func (c * conn ) invoke (
286267 ctx context.Context ,
287268 method string ,
288269 req interface {},
289270 res interface {},
290271 opts ... grpc.CallOption ,
291272) (err error ) {
292- defer func () {
293- if err != nil && errors .MustPessimizeEndpoint (err ) {
294- c .pessimize (ctx , err )
295- }
296- }()
297-
298273 var cc * grpc.ClientConn
299274 cc , err = c .take (ctx )
300275 if err != nil {
@@ -368,12 +343,6 @@ func (c *conn) newStream(
368343 method string ,
369344 opts ... grpc.CallOption ,
370345) (_ grpc.ClientStream , err error ) {
371- defer func () {
372- if err != nil && errors .MustPessimizeEndpoint (err ) {
373- c .pessimize (ctx , err )
374- }
375- }()
376-
377346 var cc * grpc.ClientConn
378347 cc , err = c .take (ctx )
379348 if err != nil {
@@ -449,14 +418,6 @@ func (c *conn) NewStream(
449418
450419type option func (c * conn )
451420
452- func withOnPessimize (onPessimize func (e endpoint.Endpoint )) option {
453- return func (c * conn ) {
454- if onPessimize != nil {
455- c .onPessimize = append (c .onPessimize , onPessimize )
456- }
457- }
458- }
459-
460421func withOnClose (onClose func (Conn )) option {
461422 return func (c * conn ) {
462423 if onClose != nil {
@@ -467,12 +428,11 @@ func withOnClose(onClose func(Conn)) option {
467428
468429func New (e endpoint.Endpoint , config Config , opts ... option ) Conn {
469430 c := & conn {
470- state : Created ,
471- endpoint : e ,
472- config : config ,
473- done : make (chan struct {}),
474- onClose : make ([]func (Conn ), 0 ),
475- onPessimize : make ([]func (e endpoint.Endpoint ), 0 ),
431+ state : Created ,
432+ endpoint : e ,
433+ config : config ,
434+ done : make (chan struct {}),
435+ onClose : make ([]func (Conn ), 0 ),
476436 }
477437 for _ , o := range opts {
478438 o (c )
0 commit comments