Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-pages.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJaime Martinez <jmartinez@gitlab.com>2022-06-28 02:20:19 +0300
committerJaime Martinez <jmartinez@gitlab.com>2022-06-28 02:20:19 +0300
commitcfa77848a58424c0048c3e52f48490cfd783176f (patch)
tree51c13b02992b5af16135cae92cd1b7f91fc8e219
parent9269d70e6a28686038ef42f0e4dcb519536eae8d (diff)
parent3c367960d85a5720024c47a6357c1fa1c9deabc6 (diff)
Merge branch 'fix/routing-502' into 'master'
fix: serve 404 if ctx is canceled while resolving a domain See merge request gitlab-org/gitlab-pages!796
-rw-r--r--internal/routing/middleware.go6
-rw-r--r--test/acceptance/serving_test.go3
2 files changed, 7 insertions, 2 deletions
diff --git a/internal/routing/middleware.go b/internal/routing/middleware.go
index bee7c9df..1b15f55c 100644
--- a/internal/routing/middleware.go
+++ b/internal/routing/middleware.go
@@ -1,6 +1,7 @@
package routing
import (
+ "context"
"errors"
"net/http"
@@ -19,6 +20,11 @@ func NewMiddleware(handler http.Handler, s source.Source) http.Handler {
// middleware chain and simply respond with 502 after logging this
d, err := getDomain(r, s)
if err != nil && !errors.Is(err, domain.ErrDomainDoesNotExist) {
+ if errors.Is(err, context.Canceled) {
+ httperrors.Serve404(w)
+ return
+ }
+
logging.LogRequest(r).WithError(err).Error("could not fetch domain information from a source")
httperrors.Serve502(w)
diff --git a/test/acceptance/serving_test.go b/test/acceptance/serving_test.go
index 92e9c8c7..c7aed337 100644
--- a/test/acceptance/serving_test.go
+++ b/test/acceptance/serving_test.go
@@ -569,7 +569,7 @@ func TestSlowRequests(t *testing.T) {
defer cancel()
url := httpListener.URL("/index.html")
- req, err := http.NewRequestWithContext(ctx, "GET", url, nil)
+ req, err := http.NewRequestWithContext(ctx, http.MethodGet, url, nil)
require.NoError(t, err)
req.Host = "group.gitlab-example.com"
@@ -578,7 +578,6 @@ func TestSlowRequests(t *testing.T) {
require.Error(t, err, "cancelling the context should trigger this error")
require.Eventually(t, func() bool {
- require.Contains(t, logBuf.String(), "context done: context canceled", "error mismatch")
require.Contains(t, logBuf.String(), "\"status\":404", "status mismatch")
return true
}, time.Second, time.Millisecond)