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"
|
"encoding/base64"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"time"
|
"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 {
|
func (e *Thumbnail) Screenshot(ctx context.Context, req *thumbnail.ScreenshotRequest, rsp *thumbnail.ScreenshotResponse) error {
|
||||||
imageName := uuid.New().String() + ".png"
|
imageName := uuid.New().String() + ".png"
|
||||||
imagePath := filepath.Join(screenshotPath, imageName)
|
imagePath := filepath.Join(screenshotPath, imageName)
|
||||||
|
defer func() {
|
||||||
|
os.Remove(imagePath)
|
||||||
|
}()
|
||||||
width := "800"
|
width := "800"
|
||||||
height := "600"
|
height := "600"
|
||||||
if req.Width != 0 {
|
if req.Width != 0 {
|
||||||
@@ -39,8 +43,10 @@ func (e *Thumbnail) Screenshot(ctx context.Context, req *thumbnail.ScreenshotReq
|
|||||||
if req.Height != 0 {
|
if req.Height != 0 {
|
||||||
height = fmt.Sprintf("%v", req.Height)
|
height = fmt.Sprintf("%v", req.Height)
|
||||||
}
|
}
|
||||||
|
cmd := exec.Command("/usr/bin/chromium-browser",
|
||||||
outp, err := exec.Command("/usr/bin/chromium-browser", "--headless", "--window-size="+width+","+height, "--no-sandbox", "--screenshot="+imagePath, "--hide-scrollbars", req.Url).CombinedOutput()
|
"--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))
|
logger.Info(string(outp))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Error(string(outp) + err.Error())
|
logger.Error(string(outp) + err.Error())
|
||||||
|
|||||||
Reference in New Issue
Block a user