Compare commits

...

2 Commits
6.3.0 ... 6.3.1

Author SHA1 Message Date
Julien Neuhart
4e7f5401ec Merge pull request #241 from Tealsky/bugfix/issue-172
[bugfix/issue-172] fixing health check
2020-09-21 15:38:18 +02:00
Ophélie Volga
3fd56e8c36 [bugfix/issue-172] fixing health check 2020-09-21 14:57:16 +02:00
2 changed files with 25 additions and 9 deletions

View File

@@ -8,6 +8,7 @@ import (
"github.com/labstack/echo/v4" "github.com/labstack/echo/v4"
"github.com/thecodingmachine/gotenberg/internal/app/xhttp/pkg/context" "github.com/thecodingmachine/gotenberg/internal/app/xhttp/pkg/context"
"github.com/thecodingmachine/gotenberg/internal/app/xhttp/pkg/resource" "github.com/thecodingmachine/gotenberg/internal/app/xhttp/pkg/resource"
"github.com/thecodingmachine/gotenberg/internal/pkg/chrome"
"github.com/thecodingmachine/gotenberg/internal/pkg/conf" "github.com/thecodingmachine/gotenberg/internal/pkg/conf"
"github.com/thecodingmachine/gotenberg/internal/pkg/printer" "github.com/thecodingmachine/gotenberg/internal/pkg/printer"
"github.com/thecodingmachine/gotenberg/internal/pkg/xerror" "github.com/thecodingmachine/gotenberg/internal/pkg/xerror"
@@ -69,7 +70,17 @@ func pingHandler(c echo.Context) error {
const op string = "xhttp.pingHandler" const op string = "xhttp.pingHandler"
ctx := context.MustCastFromEchoContext(c) ctx := context.MustCastFromEchoContext(c)
logger := ctx.XLogger() logger := ctx.XLogger()
config := ctx.Config()
logger.DebugOp(op, "handling ping request...") logger.DebugOp(op, "handling ping request...")
if !config.DisableGoogleChrome() {
_, err := chrome.IsViable(logger)
if err != nil {
return xerror.New(op, err)
}
}
return nil return nil
} }

View File

@@ -31,7 +31,8 @@ func Start(logger xlog.Logger, ignoreCertificateErrors bool) error {
} }
// if the process failed to start correctly, // if the process failed to start correctly,
// we have to restart it. // we have to restart it.
if !isViable(logger) { isViable, _ := IsViable(logger)
if !isViable {
return restart(logger, cmd.Process, ignoreCertificateErrors) return restart(logger, cmd.Process, ignoreCertificateErrors)
} }
return nil return nil
@@ -117,7 +118,8 @@ func restart(logger xlog.Logger, proc *os.Process, ignoreCertificateErrors bool)
} }
// if the process failed to restart correctly, // if the process failed to restart correctly,
// we have to restart it again. // we have to restart it again.
if !isViable(logger) { isViable, _ := IsViable(logger)
if !isViable {
return restart(logger, cmd.Process, ignoreCertificateErrors) return restart(logger, cmd.Process, ignoreCertificateErrors)
} }
return nil return nil
@@ -128,12 +130,13 @@ func restart(logger xlog.Logger, proc *os.Process, ignoreCertificateErrors bool)
return nil return nil
} }
func isViable(logger xlog.Logger) bool { // IsViable checks if Google Chrome is healthy.
func IsViable(logger xlog.Logger) (bool, error) {
const ( const (
op string = "chrome.isViable" op string = "chrome.IsViable"
maxViabilityTests int = 20 maxViabilityTests int = 20
) )
viable := func() bool { viable := func() (bool, error) {
ctx, cancel := context.WithCancel(context.Background()) ctx, cancel := context.WithCancel(context.Background())
defer cancel() defer cancel()
endpoint := "http://localhost:9222" endpoint := "http://localhost:9222"
@@ -149,21 +152,23 @@ func isViable(logger xlog.Logger) bool {
"Google Chrome headless is not viable as endpoint returned '%v'", "Google Chrome headless is not viable as endpoint returned '%v'",
err.Error(), err.Error(),
) )
return false return false, err
} }
logger.DebugOpf( logger.DebugOpf(
op, op,
"Google Chrome headless is viable as endpoint returned '%v'", "Google Chrome headless is viable as endpoint returned '%v'",
v, v,
) )
return true return true, nil
} }
result := false result := false
var err error
for i := 0; i < maxViabilityTests && !result; i++ { for i := 0; i < maxViabilityTests && !result; i++ {
warmup(logger) warmup(logger)
result = viable() result, err = viable()
} }
return result return result, err
} }
func warmup(logger xlog.Logger) { func warmup(logger xlog.Logger) {