diff options
| author | Kyren223 <Kyren223@proton.me> | 2025-02-04 19:30:30 +0200 |
|---|---|---|
| committer | Kyren223 <Kyren223@proton.me> | 2025-02-04 19:30:30 +0200 |
| commit | fe520e219c34d8fe11cadf40c577eba4e3a2784c (patch) | |
| tree | 3efc7bfca6715249338858c402b7fa2d47484ea5 | |
| parent | d9ae3018180e12c8b79361ef58c9e9e7114d80aa (diff) | |
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
| -rw-r--r-- | internal/server/server.go | 8 |
1 files changed, 6 insertions, 2 deletions
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() { |
