Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

compress/gzip: SetReadDeadline take no effect when wrapping a net.Conn with Reader #28052

xxxsen opened this issue Oct 6, 2018 · 2 comments


None yet
3 participants
Copy link

commented Oct 6, 2018

Please answer these questions before submitting your issue. Thanks!

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

go version go1.9.2 windows/amd64

Does this issue reproduce with the latest release?


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

set GOARCH=amd64
set GOBIN=
set GOEXE=.exe
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOOS=windows
set GOPATH=D:\GoProj\wcf\wcf;D:\GoPath
set GOROOT=C:\Go
set GOTOOLDIR=C:\Go\pkg\tool\windows_amd64
set GCCGO=gccgo
set CC=gcc
set GOGCCFLAGS=-m64 -mthreads -fmessage-length=0
set CXX=g++
set CGO_CFLAGS=-g -O2
set CGO_FFLAGS=-g -O2
set CGO_LDFLAGS=-g -O2
set PKG_CONFIG=pkg-config

What did you do?

I wrap a network connection with gzip reader and SetReadDeadline for it, but it take no effect when an timeout error occur

code in gunzip.go

func (z *Reader) Read(p []byte) (n int, err error) {
	if z.err != nil {
		return 0, z.err    //** when an error occur, it has no way to go next **

	n, z.err = z.decompressor.Read(p)    //** it may return a timeout error when the reader wrap a network connection **
	z.digest = crc32.Update(z.digest, crc32.IEEETable, p[:n])
	z.size += uint32(n)
	if z.err != io.EOF {
		// In the normal case we return here.
		return n, z.err

What did you expect to see?

SetReadDeadline take effect and I could retry Read operation when timeout occur

What did you see instead?

SetReadDeadline make no effect

@agnivade agnivade changed the title SetReadDeadline take no effect when use gzip reader compress/gzip: SetReadDeadline take no effect when wrapping a net.Conn with Reader Oct 7, 2018

@agnivade agnivade added this to the Unplanned milestone Oct 7, 2018


This comment has been minimized.

Copy link

commented Oct 7, 2018

Thanks. Interesting scenario.

/cc @dsnet


This comment has been minimized.

Copy link

commented Feb 5, 2019

This problem doesn't seem specific to compress/gzip, but any wrapping reader. Most of the io.Reader implementations in the standard library are sticky about read errors. It seems that there needs to be a more general solution where certain Read errors are recognized as non-fatal (and also leaves the reader in a consistent state).

I should also note that a generalized solution should also think about how timeout errors on write are handled (since the generalized problem applies to both reading and writing).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.