Skip to content

compress/gzip: panic in Writer.Close() #18883

@WillSewell

Description

@WillSewell

What version of Go are you using (go version)?

go1.7.5 darwin/amd64

What operating system and processor architecture are you using (go env)?

GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/will/src/go"
GORACE=""
GOROOT="/usr/local/Cellar/go/1.7.5/libexec"
GOTOOLDIR="/usr/local/Cellar/go/1.7.5/libexec/pkg/tool/darwin_amd64"
CC="clang"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/bm/zycksyvx1h39404g4v7wk42c0000gn/T/go-build363334644=/tmp/go-build -gno-record-gcc-switches -fno-common"
CXX="clang++"
CGO_ENABLED="1"

But I was cross compiling with CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -installsuffix cgo.

And ran it on

cat /etc/lsb-release
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=16.04
DISTRIB_CODENAME=xenial
DISTRIB_DESCRIPTION="Ubuntu 16.04.1 LTS"

On that machine, it is running in docker container (docker version: Docker version 1.13.0, build 49bf474) using the base image alpine:3.3.

What did you do?

We wrap an http.ResponseWriter in gzip.Writer. When the CloseNotifer of the http.ResponseWriter fires, we call Writer.Close().

The source code of this file is here.

I am aware this might not be the correct thing to do since closing the gzip.Writer will attempt to flush to a closed connection, but I wouldn't have expected such a low-level panic as the symptom.

What did you expect to see?

Either it to have no effect, or return an error.

What did you see instead?

This code will have been executed tens of thousands of times, and this panic only occurred a single time. The single time it paniced, the error was:

Jan 29 08:09:00 ip-10-10-30-29 docker[17374]: panic: runtime error: index out of range
Jan 29 08:09:00 ip-10-10-30-29 docker[17374]: goroutine 4987 [running]:
Jan 29 08:09:00 ip-10-10-30-29 docker[17374]: panic(0x8186e0, 0xc420016060)
Jan 29 08:09:00 ip-10-10-30-29 docker[17374]: #011/usr/local/Cellar/go/1.7.4_2/libexec/src/runtime/panic.go:500 +0x1a1
Jan 29 08:09:00 ip-10-10-30-29 docker[17374]: compress/flate.(*huffmanBitWriter).indexTokens(0xc420f743c0, 0xc422be4000, 0x2, 0x4001, 0xd, 0x76ba80)
Jan 29 08:09:00 ip-10-10-30-29 docker[17374]: #011/usr/local/Cellar/go/1.7.4_2/libexec/src/compress/flate/huffman_bit_writer.go:559 +0x2a8
Jan 29 08:09:00 ip-10-10-30-29 docker[17374]: compress/flate.(*huffmanBitWriter).writeBlock(0xc420f743c0, 0xc422be4000, 0x2, 0x4001, 0x0, 0xc423456841, 0x7, 0xf7bf)
Jan 29 08:09:00 ip-10-10-30-29 docker[17374]: #011/usr/local/Cellar/go/1.7.4_2/libexec/src/compress/flate/huffman_bit_writer.go:448 +0xa3
Jan 29 08:09:00 ip-10-10-30-29 docker[17374]: compress/flate.(*compressor).writeBlock(0xc4262c4000, 0xc422be4000, 0x1, 0x4001, 0x848, 0x7, 0x0)
Jan 29 08:09:00 ip-10-10-30-29 docker[17374]: #011/usr/local/Cellar/go/1.7.4_2/libexec/src/compress/flate/deflate.go:166 +0xba
Jan 29 08:09:00 ip-10-10-30-29 docker[17374]: compress/flate.(*compressor).deflate(0xc4262c4000)
Jan 29 08:09:00 ip-10-10-30-29 docker[17374]: #011/usr/local/Cellar/go/1.7.4_2/libexec/src/compress/flate/deflate.go:410 +0xb27
Jan 29 08:09:00 ip-10-10-30-29 docker[17374]: compress/flate.(*compressor).close(0xc4262c4000, 0xc4202e0dc0, 0xc42035cc98)
Jan 29 08:09:00 ip-10-10-30-29 docker[17374]: #011/usr/local/Cellar/go/1.7.4_2/libexec/src/compress/flate/deflate.go:636 +0x50
Jan 29 08:09:00 ip-10-10-30-29 docker[17374]: compress/flate.(*Writer).Close(0xc4262c4000, 0x405fb5, 0x7efea0)
Jan 29 08:09:00 ip-10-10-30-29 docker[17374]: #011/usr/local/Cellar/go/1.7.4_2/libexec/src/compress/flate/deflate.go:720 +0x2d
Jan 29 08:09:00 ip-10-10-30-29 docker[17374]: compress/gzip.(*Writer).Close(0xc4262a3810, 0xc42035cc40, 0x0)
Jan 29 08:09:00 ip-10-10-30-29 docker[17374]: #011/usr/local/Cellar/go/1.7.4_2/libexec/src/compress/gzip/gzip.go:240 +0x6c
Jan 29 08:09:00 ip-10-10-30-29 docker[17374]: github.com/pusher/feeds/vendor/github.com/pusher/httputil2.(*gzipResponseWriter).CloseNotify.func1(0xc42035cc40, 0xc4201fcf50, 0xc42035cbd0)
Jan 29 08:09:00 ip-10-10-30-29 docker[17374]: #011/Users/will/src/go/src/github.com/pusher/feeds/vendor/github.com/pusher/httputil2/gzip_middleware.go:119 +0x51
Jan 29 08:09:00 ip-10-10-30-29 docker[17374]: created by github.com/pusher/feeds/vendor/github.com/pusher/httputil2.(*gzipResponseWriter).CloseNotify
Jan 29 08:09:00 ip-10-10-30-29 docker[17374]: #011/Users/will/src/go/src/github.com/pusher/feeds/vendor/github.com/pusher/httputil2/gzip_middleware.go:121 +0xf1

This is where the panic returned from.

Metadata

Metadata

Assignees

No one assigned

    Labels

    FrozenDueToAgeWaitingForInfoIssue is not actionable because of missing required information, which needs to be provided.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions