Explorar el Código

fix context cancellation on shutdown

Mike hace 1 año
padre
commit
a10c7d610d
Se han modificado 2 ficheros con 5 adiciones y 0 borrados
  1. 2 0
      server/oscar/bos.go
  2. 3 0
      server/oscar/chat.go

+ 2 - 0
server/oscar/bos.go

@@ -175,6 +175,8 @@ func (rt BOSServer) handleNewConnection(ctx context.Context, rwc io.ReadWriteClo
 
 	defer func() {
 		sess.Close()
+		ctx, cancel := context.WithTimeout(context.Background(), 15*time.Second)
+		defer cancel()
 		if rt.DepartureNotifier != nil {
 			if err := rt.DepartureNotifier.BroadcastBuddyDeparted(ctx, sess); err != nil {
 				rt.Logger.ErrorContext(ctx, "error sending buddy departure notifications", "err", err.Error())

+ 3 - 0
server/oscar/chat.go

@@ -8,6 +8,7 @@ import (
 	"log/slog"
 	"net"
 	"sync"
+	"time"
 
 	"github.com/mk6i/retro-aim-server/config"
 	"github.com/mk6i/retro-aim-server/wire"
@@ -100,6 +101,8 @@ func (rt ChatServer) handleNewConnection(ctx context.Context, rwc io.ReadWriteCl
 	}
 
 	defer func() {
+		ctx, cancel := context.WithTimeout(context.Background(), 15*time.Second)
+		defer cancel()
 		chatSess.Close()
 		rt.SignoutChat(ctx, chatSess)
 	}()