From 5247c6c545d678ef164e785082424202b5dbdcfb Mon Sep 17 00:00:00 2001 From: Paul van Santen Date: Thu, 27 Jun 2024 11:36:03 +0200 Subject: [PATCH 1/2] HTTP: Pass some send errors back to sender for easier debugging --- http/client.go | 2 +- http/http_handlers.go | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/http/client.go b/http/client.go index a2f6bbe..03b2ca5 100644 --- a/http/client.go +++ b/http/client.go @@ -302,7 +302,7 @@ func (c *Client) doSendStream(req *http.Request, pipeWrtr *io.PipeWriter, cancel case http.StatusNotFound: return ErrDatasetNotFound default: - return fmt.Errorf("unexpected status %d sending stream", resp.StatusCode) + return fmt.Errorf("unexpected status %d sending stream, server error: %s", resp.StatusCode, resp.Header.Get(HeaderError)) } } diff --git a/http/http_handlers.go b/http/http_handlers.go index 3f3e974..36490eb 100644 --- a/http/http_handlers.go +++ b/http/http_handlers.go @@ -29,6 +29,7 @@ const ( const ( HeaderResumeReceiveToken = "X-Receive-Resume-Token" HeaderResumeReceivedBytes = "X-Received-Bytes" + HeaderError = "X-Error" ) type ReceiveProperties map[string]string @@ -253,6 +254,7 @@ func (h *HTTP) handleReceiveSnapshot(w http.ResponseWriter, req *http.Request, l if !validIdentifier(filesystem) || (snapshot != "" && !validIdentifier(snapshot)) { logger.Info("zfs.http.handleReceiveSnapshot: Invalid identifier") + w.Header().Set(HeaderError, "invalid identifier") w.WriteHeader(http.StatusBadRequest) return } @@ -271,6 +273,7 @@ func (h *HTTP) handleReceiveSnapshot(w http.ResponseWriter, req *http.Request, l if datasetResumeToken == "" && givenResumeToken != "" { logger.Info("zfs.http.handleReceiveSnapshot: Got resume token but found none on dataset", "resumeToken", givenResumeToken) + w.Header().Set(HeaderError, "no resume token on dataset") w.WriteHeader(http.StatusPreconditionFailed) return } @@ -280,6 +283,7 @@ func (h *HTTP) handleReceiveSnapshot(w http.ResponseWriter, req *http.Request, l "givenResumeToken", givenResumeToken, "actualResumeToken", datasetResumeToken, ) + w.Header().Set(HeaderError, "invalid resume token") w.WriteHeader(http.StatusConflict) return } @@ -300,6 +304,7 @@ func (h *HTTP) handleReceiveSnapshot(w http.ResponseWriter, req *http.Request, l }) if err != nil { logger.Error("zfs.http.handleReceiveSnapshot: Error storing", "error", err) + w.Header().Set(HeaderError, err.Error()) w.WriteHeader(http.StatusNotFound) return } From 3dd77cba7856d34848db4dceabca25100902f144 Mon Sep 17 00:00:00 2001 From: Paul van Santen Date: Thu, 27 Jun 2024 11:52:09 +0200 Subject: [PATCH 2/2] Fix status code on store dataset error: Internal --- http/http_handlers.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/http/http_handlers.go b/http/http_handlers.go index 36490eb..3f2b28e 100644 --- a/http/http_handlers.go +++ b/http/http_handlers.go @@ -305,7 +305,7 @@ func (h *HTTP) handleReceiveSnapshot(w http.ResponseWriter, req *http.Request, l if err != nil { logger.Error("zfs.http.handleReceiveSnapshot: Error storing", "error", err) w.Header().Set(HeaderError, err.Error()) - w.WriteHeader(http.StatusNotFound) + w.WriteHeader(http.StatusInternalServerError) return }