Skip to content

Commit a10c7d6

Browse files
committed
fix context cancellation on shutdown
1 parent b951334 commit a10c7d6

File tree

2 files changed

+5
-0
lines changed

2 files changed

+5
-0
lines changed

server/oscar/bos.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,8 @@ func (rt BOSServer) handleNewConnection(ctx context.Context, rwc io.ReadWriteClo
175175

176176
defer func() {
177177
sess.Close()
178+
ctx, cancel := context.WithTimeout(context.Background(), 15*time.Second)
179+
defer cancel()
178180
if rt.DepartureNotifier != nil {
179181
if err := rt.DepartureNotifier.BroadcastBuddyDeparted(ctx, sess); err != nil {
180182
rt.Logger.ErrorContext(ctx, "error sending buddy departure notifications", "err", err.Error())

server/oscar/chat.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"log/slog"
99
"net"
1010
"sync"
11+
"time"
1112

1213
"github.com/mk6i/retro-aim-server/config"
1314
"github.com/mk6i/retro-aim-server/wire"
@@ -100,6 +101,8 @@ func (rt ChatServer) handleNewConnection(ctx context.Context, rwc io.ReadWriteCl
100101
}
101102

102103
defer func() {
104+
ctx, cancel := context.WithTimeout(context.Background(), 15*time.Second)
105+
defer cancel()
103106
chatSess.Close()
104107
rt.SignoutChat(ctx, chatSess)
105108
}()

0 commit comments

Comments
 (0)