Update MTPROXY_CHECK_TIMEOUT to 45s in docker-compose and documentation; adjust default timeout handling in code for improved performance under slow network conditions.
This commit is contained in:
@@ -3,6 +3,7 @@ package checkresult
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net"
|
||||
|
||||
"mtproxy_checker/internal/checker"
|
||||
)
|
||||
@@ -18,5 +19,9 @@ func Classify(err error) (exitCode int, message string) {
|
||||
if errors.Is(err, context.DeadlineExceeded) {
|
||||
return 4, "timeout"
|
||||
}
|
||||
var ne net.Error
|
||||
if errors.As(err, &ne) && ne.Timeout() {
|
||||
return 4, "timeout"
|
||||
}
|
||||
return 1, err.Error()
|
||||
}
|
||||
|
||||
@@ -113,6 +113,9 @@ func isResPQ(mtInner []byte) bool {
|
||||
// Consumes 0x17 payloads with dec so the CTR stream stays aligned with the server; discards MTProto frames until idle.
|
||||
func DrainPostInitEE(ctx context.Context, br *bufio.Reader, conn net.Conn, dec cipher.Stream, maxWait time.Duration) error {
|
||||
end := time.Now().Add(maxWait)
|
||||
if d, ok := ctx.Deadline(); ok && d.Before(end) {
|
||||
end = d
|
||||
}
|
||||
var acc []byte
|
||||
const maxDrain = 256 << 10
|
||||
drained := 0
|
||||
@@ -122,10 +125,15 @@ func DrainPostInitEE(ctx context.Context, br *bufio.Reader, conn net.Conn, dec c
|
||||
return ctx.Err()
|
||||
default:
|
||||
}
|
||||
d := 200 * time.Millisecond
|
||||
d := 500 * time.Millisecond
|
||||
if rem := time.Until(end); rem < d {
|
||||
d = rem
|
||||
}
|
||||
if cd, ok := ctx.Deadline(); ok {
|
||||
if rem := time.Until(cd); rem < d {
|
||||
d = rem
|
||||
}
|
||||
}
|
||||
if d <= 0 {
|
||||
return nil
|
||||
}
|
||||
@@ -185,22 +193,27 @@ func VerifyResPQ(ctx context.Context, conn net.Conn, enc, dec cipher.Stream, tls
|
||||
|
||||
deadline, ok := ctx.Deadline()
|
||||
if !ok {
|
||||
deadline = time.Now().Add(15 * time.Second)
|
||||
deadline = time.Now().Add(60 * time.Second)
|
||||
}
|
||||
|
||||
var acc []byte
|
||||
|
||||
const maxAcc = 256 << 10
|
||||
// Один read ждёт ответ DC; 3s мало при нагрузке/гео — держим до 30s, но не дольше ctx.
|
||||
const perReadSlack = 30 * time.Second
|
||||
for time.Now().Before(deadline) {
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
return ctx.Err()
|
||||
default:
|
||||
}
|
||||
chunkDeadline := time.Now().Add(3 * time.Second)
|
||||
chunkDeadline := time.Now().Add(perReadSlack)
|
||||
if chunkDeadline.After(deadline) {
|
||||
chunkDeadline = deadline
|
||||
}
|
||||
if !chunkDeadline.After(time.Now().Add(50 * time.Millisecond)) {
|
||||
return fmt.Errorf("%w: not enough time left waiting for resPQ", context.DeadlineExceeded)
|
||||
}
|
||||
_ = conn.SetReadDeadline(chunkDeadline)
|
||||
var chunk []byte
|
||||
var rerr error
|
||||
|
||||
Reference in New Issue
Block a user