| 903 | } |
| 904 | |
| 905 | func (e *Endpoint) stop() error { |
| 906 | // Drain the subscription. If the connection is closed, draining is not possible |
| 907 | // but we should still remove the endpoint from the service. |
| 908 | if err := e.subscription.Drain(); err != nil && !errors.Is(err, nats.ErrConnectionClosed) { |
| 909 | return fmt.Errorf("draining subscription for request handler: %w", err) |
| 910 | } |
| 911 | for i := 0; i < len(e.service.endpoints); i++ { |
| 912 | if e.service.endpoints[i].Subject == e.Subject { |
| 913 | if i != len(e.service.endpoints)-1 { |
| 914 | e.service.endpoints = append(e.service.endpoints[:i], e.service.endpoints[i+1:]...) |
| 915 | } else { |
| 916 | e.service.endpoints = e.service.endpoints[:i] |
| 917 | } |
| 918 | i++ |
| 919 | } |
| 920 | } |
| 921 | return nil |
| 922 | } |
| 923 | |
| 924 | func (e *Endpoint) reset() { |
| 925 | e.stats = EndpointStats{ |