diff options
| author | Kyren223 <Kyren223@proton.me> | 2025-01-06 18:23:41 +0200 |
|---|---|---|
| committer | Kyren223 <Kyren223@proton.me> | 2025-01-06 18:23:41 +0200 |
| commit | 63790c069fbca0c3548fdaa58148e6cefdf477d5 (patch) | |
| tree | 8ba0e84d0334e13fcb36134789791dadfb0bfde7 /internal/server/session | |
| parent | 1a218730e9a0c16fd71f4606adfde5862be2e7b7 (diff) | |
Server and client now properly handle the same user logging in from
different locations, fixed the issue where it'd only work for the first
time by checking if the addresses match before remove the session
Diffstat (limited to 'internal/server/session')
| -rw-r--r-- | internal/server/session/session.go | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/internal/server/session/session.go b/internal/server/session/session.go index 88a19e7..a904d39 100644 --- a/internal/server/session/session.go +++ b/internal/server/session/session.go @@ -4,6 +4,7 @@ import ( "context" "crypto/ed25519" "crypto/rand" + "log" "net" "sync" "time" @@ -99,7 +100,7 @@ func (s *Session) Read(ctx context.Context) (packet.Packet, bool) { } func (s *Session) Close() { - timeout := 1 * time.Second + timeout := 10 * time.Millisecond ctx, cancel := context.WithTimeout(context.Background(), timeout) payload := &packet.Error{ Error: "new connection from another location, closing this one", @@ -109,5 +110,13 @@ func (s *Session) Close() { s.Write(ctx, pkt) cancel() + // Add some delay before canceling to let the writer enough time to + // actually write that into the connection + // HACK: consider just giving session the private connection and to + // write directly so we don't have to wait + time.Sleep(100 * time.Millisecond) + + log.Println(s.addr, "closed due to new connection from another location") + s.cancel() } |
