mirror of
https://gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake.git
synced 2025-10-13 11:11:30 -04:00
Add context with timeout for client requests
Client timeouts are currently counted from when the client is matched with a proxy. Instead, count client timeouts from the moment when the request is received. Closes #40449
This commit is contained in:
parent
db0364ef87
commit
8343bbc336
6 changed files with 25 additions and 7 deletions
|
@ -2,12 +2,14 @@ package main
|
|||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"log"
|
||||
"net/http"
|
||||
"os"
|
||||
"time"
|
||||
|
||||
"gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake/v2/common/messages"
|
||||
"gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake/v2/common/util"
|
||||
|
@ -132,6 +134,9 @@ snowflake proxy, which responds with the SDP answer to be sent in
|
|||
the HTTP response back to the client.
|
||||
*/
|
||||
func clientOffers(i *IPC, w http.ResponseWriter, r *http.Request) {
|
||||
ctx, cancel := context.WithTimeout(r.Context(), ClientTimeout*time.Second)
|
||||
defer cancel()
|
||||
|
||||
body, err := io.ReadAll(http.MaxBytesReader(w, r.Body, readLimit))
|
||||
if err != nil {
|
||||
log.Printf("Error reading client request: %s", err.Error())
|
||||
|
@ -163,6 +168,7 @@ func clientOffers(i *IPC, w http.ResponseWriter, r *http.Request) {
|
|||
Body: body,
|
||||
RemoteAddr: util.GetClientIp(r),
|
||||
RendezvousMethod: messages.RendezvousHttp,
|
||||
Context: ctx,
|
||||
}
|
||||
|
||||
var response []byte
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue