From 63790c069fbca0c3548fdaa58148e6cefdf477d5 Mon Sep 17 00:00:00 2001 From: Kyren223 Date: Mon, 6 Jan 2025 18:23:41 +0200 Subject: 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 --- internal/server/session/session.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'internal/server/session/session.go') 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() } -- cgit v1.3.1