Open yourchanges opened 1 year ago
here is the test code:
func ResizedBybimg(ext string, read io.ReadSeeker, width, height int, mode string) (resized io.ReadSeeker, w int, h int) {
if width == 0 && height == 0 {
return read, 0, 0
}
srcImage, _, err := image.Decode(read)
if err == nil {
bounds := srcImage.Bounds()
if bounds.Dx() > width && width != 0 || bounds.Dy() > height && height != 0 {
read.Seek(0, 0)
imageBuf, _ := io.ReadAll(read)
dstImageBuff, err := bimg.NewImage(imageBuf).ForceResize(width, height)
if err == nil {
return bytes.NewReader(dstImageBuff), width, height
}
log.Println("bimg resize error", err)
} else {
read.Seek(0, 0)
return read, bounds.Dx(), bounds.Dy()
}
} else {
log.Println("image decode error", err)
}
read.Seek(0, 0)
return read, 0, 0
}
ENV: bimg 1.1.6 libvips 8.10.6 on centos7
when run in our prod env, the server cashed by "runtime: program exceeds 10000-thread limit fatal error: thread exhaustion"
here are 9927 cgo-goroutine (block cgo goroutine === os-thread)+ default owned os-thread, so our process crashed
here is the cgo-goroutine's detail info
it seems the following code not work correctly: