From fe520e219c34d8fe11cadf40c577eba4e3a2784c Mon Sep 17 00:00:00 2001 From: Kyren223 Date: Tue, 4 Feb 2025 19:30:30 +0200 Subject: Server now uses a new context for api requests to make sure they still get completed even if the user disconnects, this is not ideal and should be reworked in the future --- internal/server/server.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'internal/server/server.go') diff --git a/internal/server/server.go b/internal/server/server.go index e83fcb4..153f612 100644 --- a/internal/server/server.go +++ b/internal/server/server.go @@ -369,7 +369,7 @@ func processRequest(ctx context.Context, sess *session.Session, request packet.P response = timeout(10*time.Millisecond, api.TrustUser, ctx, sess, request) case *packet.SetLastReadMessages: - response = timeout(100*time.Millisecond, api.SetLastReadMessages, ctx, sess, request) + response = timeout(50*time.Millisecond, api.SetLastReadMessages, ctx, sess, request) default: response = &packet.Error{Error: "use of disallowed packet type for request"} @@ -389,7 +389,11 @@ func timeout[T packet.Payload]( ) packet.Payload { // TODO: Remove the channel and just wait directly? responseChan := make(chan packet.Payload) - ctx, cancel := context.WithTimeout(ctx, timeoutDuration) + + // FIXME: currently just ignoring the given context + // this fixes the issue where the client disconnects so the server + // doesn't bother and cancels the request + ctx, cancel := context.WithTimeout(context.Background(), timeoutDuration) defer cancel() go func() { -- cgit v1.3.1