-
Notifications
You must be signed in to change notification settings - Fork 352
Closed
Description
My server crash after 10-20 min after start.
caller code:
var gCompressPool5 sync.Pool
func mustFlateCompressWithBufferToBufWPool5(inb []byte,bufW *bytes.Buffer) {
var flateW *flate.Writer
obj:=gCompressPool5.Get()
if obj==nil{
var err error
flateW,err = flate.NewWriter(bufW,4)
if err!=nil{
panic(err)
}
}else{
flateW = obj.(*flate.Writer)
flateW.Reset(bufW)
}
_, err := flateW.Write(inb)
if err != nil {
flateW.Close()
flateW.Reset(nil)
gCompressPool5.Put(flateW)
panic(err)
}
err = flateW.Close()
flateW.Reset(nil)
gCompressPool5.Put(flateW)
if err != nil {
panic(err)
}
}runtime error: slice bounds out of range
goroutine 82 [running]:
github.com/klauspost/compress/flate.(*fastGen).matchlenLong(0xc0288e8000, 0x5386ca610003395c, 0xc028aea000, 0x3fffc, 0x100000, 0x13)
github.com/klauspost/compress/flate/fast_encoder.go:208 +0xb6
github.com/klauspost/compress/flate.(*fastEncL4).Encode(0xc0288e8000, 0xc02bcf2090, 0xc02bf88000, 0xffff, 0xffff)
github.com/klauspost/compress/flate/level4.go:127 +0x4db
github.com/klauspost/compress/flate.(*compressor).storeFast(0xc02bcf2000)
github.com/klauspost/compress/flate/deflate.go:590 +0x1c1
github.com/klauspost/compress/flate.(*compressor).write(0xc02bcf2000, 0xc02176bffc, 0x1c80ae, 0x18a004, 0x113d380, 0xc007352960, 0xc007352960)
github.com/klauspost/compress/flate/deflate.go:614 +0x81
github.com/klauspost/compress/flate.(*Writer).Write(0xc02bcf2000, 0xc02172c000, 0x1c80ae, 0x1ca000, 0xc000d2b568, 0x44b894, 0xc015512199)
github.com/klauspost/compress/flate/deflate.go:781 +0x4b
...
I have tried a single thread, it crash like this too(after one hour):
var gCompressWriter *flate.Writer
var gCompressWriterLocker sync.Mutex
func mustFlateCompressWithBufferToBufWPool3(inb []byte,bufW *bytes.Buffer) {
gCompressWriterLocker.Lock()
defer gCompressWriterLocker.Unlock()
if gCompressWriter==nil{
var err error
gCompressWriter,err = flate.NewWriter(bufW,4)
if err!=nil{
panic(err)
}
}else{
gCompressWriter.Reset(bufW)
}
_, err := gCompressWriter.Write(inb)
if err != nil {
gCompressWriter.Close()
gCompressWriter.Reset(nil)
panic(err)
}
err = gCompressWriter.Close()
gCompressWriter.Reset(nil)
if err != nil {
panic(err)
}
}I have tried flate from golang 1.11.6, it never crash after 3 hours. (but use more cpu resource than this library)
I have tried flate from https://github.com/klauspost/compress and do not reuse the writer object, it never crash after 12 hours.(but use more cpu resource)
Workaround right now: use flate from golang 1.11.6 and sync.Pool
Metadata
Metadata
Assignees
Labels
No labels