Skip to content

Commit

Permalink
use interface
Browse files Browse the repository at this point in the history
  • Loading branch information
mattisonchao committed Feb 17, 2025
1 parent 4219b48 commit 695f1eb
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
6 changes: 4 additions & 2 deletions server/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package server
import (
"context"
"fmt"
"io"
"log/slog"
"net/url"
"sync"
Expand All @@ -30,6 +31,7 @@ import (
// --- Session

type session struct {
io.Closer
sync.Mutex
id SessionId
clientIdentity string
Expand Down Expand Up @@ -75,7 +77,7 @@ func startSession(sessionId SessionId, sessionMetadata *proto.SessionMetadata, s
return s
}

func (s *session) closeChannels() {
func (s *session) Close() {
s.Lock()
defer s.Unlock()
s.cancel()
Expand Down Expand Up @@ -168,7 +170,7 @@ func (s *session) waitForHeartbeats() {
case <-timeoutCh:
s.log.Warn("Session expired")

s.closeChannels()
s.Close()
err := s.delete()

if err != nil {
Expand Down
5 changes: 3 additions & 2 deletions server/session_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,8 +202,9 @@ func (sm *sessionManager) CloseSession(request *proto.CloseSessionRequest) (*pro
}
sm.sessions.Remove(s.id)
sm.Unlock()
s.closeChannels()

s.log.Info("Session closing")
s.Close()
err = s.delete()
if err != nil {
return nil, err
Expand Down Expand Up @@ -294,7 +295,7 @@ func (sm *sessionManager) Close() error {
sm.cancel()
for _, s := range sm.sessions.Values() {
sm.sessions.Remove(s.id)
s.closeChannels()
s.Close()
}

sm.activeSessions.Unregister()
Expand Down

0 comments on commit 695f1eb

Please sign in to comment.