From 9066acc325329ae6b7a6811b96555baac49f1c9d Mon Sep 17 00:00:00 2001 From: Petr Date: Tue, 30 Jun 2026 11:13:49 +0200 Subject: [PATCH] chore(gopher): extract dial timeout constant --- internal/protocol/gopher/gopher.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/internal/protocol/gopher/gopher.go b/internal/protocol/gopher/gopher.go index 332d311..17dd57b 100644 --- a/internal/protocol/gopher/gopher.go +++ b/internal/protocol/gopher/gopher.go @@ -34,6 +34,12 @@ const ( typeSearch = '7' // index search ) +// dialTimeout caps the time spent establishing a TCP connection and +// waiting for the first response byte. Generous enough for slow Gopher +// servers, short enough that a stalled connection does not block the +// caller indefinitely. +const dialTimeout = 30 * time.Second + // Protocol implements gopher:// downloads (RFC 1436). type Protocol struct { *protocol.BaseProtocol @@ -68,12 +74,12 @@ func (p *Protocol) Download(ctx context.Context, req *core.DownloadRequest) (*co } addr := net.JoinHostPort(host, port) - conn, err := net.DialTimeout("tcp", addr, 30*time.Second) + conn, err := net.DialTimeout("tcp", addr, dialTimeout) if err != nil { return nil, core.NewNetworkError("failed to connect to gopher server", err, core.SafeURL(req.URL)) } defer conn.Close() - conn.SetDeadline(time.Now().Add(30 * time.Second)) + conn.SetDeadline(time.Now().Add(dialTimeout)) // Close the connection when the context is cancelled so any // blocking Read returns immediately instead of waiting for the