Skip to content

net/http: Server.Close may not able to close all connections #48642

Closed
@shinny-chengzhi

Description

@shinny-chengzhi

I encountered lingering connection after calling Server.Close and it's not closed by Server.Close

Here is reproducible example: https://play.golang.org/p/9aLVDwWPQhH

The problem is http/server.go: Server.Serve function didn't check if Server is already closed before calling handler, and if Server.Close been called after l.Accept return but before c.setState(c.rwc, StateNew, runHooks), the new connection is not registered in the activeConn map when Server.Close try to close all connections.

The example code simulate this condition by sleep one second during ConnContext call. Program can exit corrected if this sleep is removed.

Metadata

Metadata

Assignees

No one assigned

    Labels

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

    Type

    No type

    Projects

    Status

    Done

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions