From 0f30839fdba860d570ba01f16b265a5cdd85e5e4 Mon Sep 17 00:00:00 2001 From: Gareth George Date: Sun, 13 Jul 2025 16:42:49 -0700 Subject: [PATCH] more sync api bug fixes --- internal/api/syncapi/authentication.go | 4 ---- internal/api/syncapi/syncapi_test.go | 3 +++ internal/api/syncapi/syncclient.go | 13 +++++++++---- internal/api/syncapi/synccommon.go | 10 +++++----- internal/api/syncapi/synchandler.go | 17 ++++++++++++----- internal/api/syncapi/syncmanager.go | 1 + 6 files changed, 30 insertions(+), 18 deletions(-) diff --git a/internal/api/syncapi/authentication.go b/internal/api/syncapi/authentication.go index 62086483..4109f354 100644 --- a/internal/api/syncapi/authentication.go +++ b/internal/api/syncapi/authentication.go @@ -39,17 +39,14 @@ func ContextWithPeer(ctx context.Context, peer *v1.Multihost_Peer, publicKey *cr // HTTP decorator for authentication middleware. func AuthenticationMiddleware(configManager *config.ConfigManager, handler http.Handler) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - zap.S().Debugf("AuthenticationMiddleware called for %s %s", r.Method, r.URL.Path) authHeader := r.Header.Get("Authorization") if authHeader == "" { - zap.S().Error("missing Authorization header in request") http.Error(w, "Unauthorized: missing authentication header", http.StatusUnauthorized) return } config, err := configManager.Get() if err != nil { - zap.S().Errorf("failed to get authorized clients from config: %v", err) http.Error(w, "Internal error", http.StatusInternalServerError) return } @@ -57,7 +54,6 @@ func AuthenticationMiddleware(configManager *config.ConfigManager, handler http. peerKey, instanceID, err := verifyAuthenticationHeader(authHeader) if err != nil { - zap.S().Errorf("failed to verify authentication header: %v", err) http.Error(w, fmt.Sprintf("Unauthorized: %v", err), http.StatusUnauthorized) return } diff --git a/internal/api/syncapi/syncapi_test.go b/internal/api/syncapi/syncapi_test.go index cd643eb6..fb0ce1eb 100644 --- a/internal/api/syncapi/syncapi_test.go +++ b/internal/api/syncapi/syncapi_test.go @@ -539,6 +539,9 @@ func tryExpectExactOperations(t *testing.T, ctx context.Context, peer *peerUnder for _, op := range ops { op.Modno = 0 } + for _, op := range wantOps { + op.Modno = 0 + } if diff := cmp.Diff(ops, wantOps, protocmp.Transform()); diff != "" { return fmt.Errorf("unexpected diff: %v", diff) } diff --git a/internal/api/syncapi/syncclient.go b/internal/api/syncapi/syncclient.go index 083dddbd..1cdb0efc 100644 --- a/internal/api/syncapi/syncclient.go +++ b/internal/api/syncapi/syncclient.go @@ -182,11 +182,11 @@ func (c *SyncClient) RunSync(ctx context.Context) { // Wait for the thread running the API loop and the thread running the stream connection to finish. wg.Wait() - delay := c.reconnectDelay - time.Since(lastConnect) + reconnectDelayWithBackoff := c.reconnectDelay if c.reconnectAttempts > 0 { - backoff := time.Duration(1<