Skip to content

net/http: Flush in TimeoutHandler for Go1.13 is broken and might need a revert #34439

Closed
@pam4

Description

@pam4

Currently (1.13) calling Flush on a ResponseWriter exposed by TimeoutHandler has some undesirable effect:

  1. it sends out default headers with a 200 OK status, ignoring whatever the caller set before (e.g. w.Header().Set(key, val) or w.WriteHeader(someOtherCode));
  2. in doing so, it prevents TimeoutHandler to respond with 503 on timeout as promised, and it produces a "superfluous response.WriteHeader call" warning;
  3. it doesn't flush anything.

https://play.golang.org/p/HmW2ETipalB

This is happening because timeoutWriter.Flush calls the underlying Flush, which in turn calls the underlying WriteHeader from a clean state: the actual header and partial body are still buffered in the wrapper (in timeoutWriter.h and timeoutWriter.wbuf).

I think TimeoutHandler supporting Flush doesn't make any sense because a TimeoutHandler doesn't know what to do until either the inner handler returns or the timeout is reached, therefore it needs to buffer the whole response until the end.

EDIT: #34198 is probably an effect.

Metadata

Metadata

Assignees

No one assigned

    Labels

    FrozenDueToAgeNeedsFixThe path to resolution is known, but the work has not been done.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions