Add context timeouts for third-party requests
Some checks failed
/ golint (push) Failing after 3m56s
Some checks failed
/ golint (push) Failing after 3m56s
Avoid hanging a goroutine for a long time.
This commit is contained in:
parent
2093ea74c4
commit
15d8966971
11 changed files with 80 additions and 5 deletions
|
|
@ -3,6 +3,7 @@ package pdf
|
|||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/Gleipnir-Technology/nidus-sync/config"
|
||||
"github.com/chromedp/cdproto/page"
|
||||
|
|
@ -13,7 +14,9 @@ import (
|
|||
func GeneratePDF(ctx context.Context, path string) ([]byte, error) {
|
||||
// create context
|
||||
chromedp.Env("CHROME_FLAGS=--no-sandbox --disable-gpu --disable-dev-shm-usage")
|
||||
chrome_ctx, cancel := chromedp.NewContext(context.Background())
|
||||
chromeCtx, chromeCancel := context.WithTimeout(context.Background(), 60*time.Second)
|
||||
defer chromeCancel()
|
||||
chrome_ctx, cancel := chromedp.NewContext(chromeCtx)
|
||||
defer cancel()
|
||||
|
||||
// capture pdf
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue