Skip to content

Sporadic 502: ReadHeaderTimeout set to 10 microseconds instead of seconds #9

Closed

Description

@gnacho

Problem

Intermittent 502 responses from the notes API behind a reverse proxy, with the proxy logging:

recv() failed (104: Connection reset by peer) while reading response header from upstream

Root cause

The HTTP server was configured with:

ReadHeaderTimeout: 10 * 1024

An untyped constant assigned to a time.Duration field is interpreted in nanoseconds, so the effective timeout was 10.24 microseconds instead of the intended 10 seconds. Any request whose headers took longer than that to arrive (second TCP segment, scheduling hiccup) got its connection killed by the server, which the proxy surfaces as a 502.

Fix

Set proper timeouts: ReadHeaderTimeout: 10 * time.Second, plus ReadTimeout/WriteTimeout 30s and IdleTimeout 120s.

Verified by hammering the public endpoint with 40 concurrent requests: all clean responses, no resets (previously the reset reproduced under bursts).

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions