mirror of
https://github.com/kevin-DL/services.git
synced 2026-01-11 19:04:35 +00:00
Fix process leak in thumbnail (#257)
This commit is contained in:
@@ -5,6 +5,7 @@ import (
|
||||
"encoding/base64"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"time"
|
||||
@@ -31,6 +32,9 @@ func NewThumbnail(imageService iproto.ImageService) *Thumbnail {
|
||||
func (e *Thumbnail) Screenshot(ctx context.Context, req *thumbnail.ScreenshotRequest, rsp *thumbnail.ScreenshotResponse) error {
|
||||
imageName := uuid.New().String() + ".png"
|
||||
imagePath := filepath.Join(screenshotPath, imageName)
|
||||
defer func() {
|
||||
os.Remove(imagePath)
|
||||
}()
|
||||
width := "800"
|
||||
height := "600"
|
||||
if req.Width != 0 {
|
||||
@@ -39,8 +43,10 @@ func (e *Thumbnail) Screenshot(ctx context.Context, req *thumbnail.ScreenshotReq
|
||||
if req.Height != 0 {
|
||||
height = fmt.Sprintf("%v", req.Height)
|
||||
}
|
||||
|
||||
outp, err := exec.Command("/usr/bin/chromium-browser", "--headless", "--window-size="+width+","+height, "--no-sandbox", "--screenshot="+imagePath, "--hide-scrollbars", req.Url).CombinedOutput()
|
||||
cmd := exec.Command("/usr/bin/chromium-browser",
|
||||
"--headless", "--window-size="+width+","+height, "--no-sandbox", "--screenshot="+imagePath,
|
||||
"--hide-scrollbars", "--disable-setuid-sandbox", "--single-process", "--no-zygote", req.Url)
|
||||
outp, err := cmd.CombinedOutput()
|
||||
logger.Info(string(outp))
|
||||
if err != nil {
|
||||
logger.Error(string(outp) + err.Error())
|
||||
|
||||
Reference in New Issue
Block a user