Skip to content

HTTP2 res.writableFinished without calling .end() #38916

@ronag

Description

@ronag

I noticed this from an assertion i production. A http2 response can become writableEnded and writableFinished without the user ever calling response.end(). I believe there is some special logic for HEAD requests that causes this behavior.

I think this is suboptimal from a streams perspective but could still be considered ok behavior. I don't think "self ending" streams are a good idea. However, from a http1 compat perspective it does differ in behavior from http1 response which can cause unexpected problems if one assumes that a http2 compat response behaves exactly like a http1 response.

I basically had something like this in our code:

function onUpstreamComplete (trailers) {
    const { res } = this

    // Ensure we don't have a bug somewhere "corrupting" state by prematurely ending or destroying response. 
    assert(!res.destroyed)
    assert(!res.writableEnded)
    assert(!res.writableFinished)
    
    writeTrailers(res, trailers)

    res.end()
} 

Metadata

Metadata

Assignees

No one assigned

    Labels

    httpIssues or PRs related to the http subsystem.http2Issues or PRs related to the http2 subsystem.streamIssues and PRs related to the stream subsystem.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions