Pass the ctx to the close function

This commit is contained in:
Zoltán Papp
2024-08-21 16:05:04 +02:00
parent 7633cca3b1
commit a208e7999c
7 changed files with 32 additions and 33 deletions
+2 -6
View File
@@ -3,7 +3,6 @@ package server
import (
"context"
"crypto/tls"
"time"
log "github.com/sirupsen/logrus"
"go.opentelemetry.io/otel/metric"
@@ -61,15 +60,12 @@ func (r *Server) Listen(cfg ListenerConfig) error {
// Close stops the relay server. If there are active connections, they will be closed gracefully. In case of a timeout,
// the connections will be forcefully closed.
func (r *Server) Close() (err error) {
func (r *Server) Close(ctx context.Context) (err error) {
// stop service new connections
if r.wSListener != nil {
err = r.wSListener.Close()
err = r.wSListener.Close(ctx)
}
// close accepted connections gracefully
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
defer cancel()
r.relay.Close(ctx)
return
}