Skip to content

net/http: allows read from Response.Body after Close #13648

Closed
@rsc

Description

@rsc

This program runs correctly in Go 1.5: it exits 0. In Go 1.6 it dies because it detects the ReadAll succeeding despite having called Body.Close.

This was masking some bad code in go get but it's a real problem in its own right: Read after Close should fail.

package main

import (
    "io/ioutil"
    "log"
    "net/http"
)

func main() {
    resp, err := http.DefaultClient.Get("https://bazil.org/fuse/fs/fstestutil?go-get=1")
    if err != nil {
        log.Fatal(err)
    }
    resp.Body.Close()
    data, err := ioutil.ReadAll(resp.Body)
    if len(data) != 0 || err == nil {
        log.Fatalf("ReadAll returned %q, %v", data, err)
    }
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions