From ff7d65041ad3fde63c8d5cc43c119fde2cc5d839 Mon Sep 17 00:00:00 2001 From: Neeraj Gupta <254676+ua741@users.noreply.github.com> Date: Tue, 5 Nov 2024 11:33:24 +0530 Subject: [PATCH 1/4] [server] Avoid immedidate sync --- server/pkg/repo/filedata/repository.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/server/pkg/repo/filedata/repository.go b/server/pkg/repo/filedata/repository.go index f2d33b97e59..e97040fa4c1 100644 --- a/server/pkg/repo/filedata/repository.go +++ b/server/pkg/repo/filedata/repository.go @@ -24,11 +24,13 @@ const ( ) func (r *Repository) InsertOrUpdate(ctx context.Context, data filedata.Row) error { + // During insert, we set the sync_locked_till to 5 minutes in the future. This is to prevent + // immediate replication of the file data row, that can result in failure of update/retry requests query := ` INSERT INTO file_data - (file_id, user_id, data_type, size, latest_bucket) + (file_id, user_id, data_type, size, latest_bucket, sync_locked_till) VALUES - ($1, $2, $3, $4, $5) + ($1, $2, $3, $4, $5, now_utc_micro_seconds() + 5 * 60 * 1000*1000) ON CONFLICT (file_id, data_type) DO UPDATE SET size = EXCLUDED.size, From a87fdfa94b1f0930bcb3d74842e6b23958666251 Mon Sep 17 00:00:00 2001 From: Neeraj Gupta <254676+ua741@users.noreply.github.com> Date: Tue, 5 Nov 2024 11:36:12 +0530 Subject: [PATCH 2/4] fix log msg --- server/pkg/controller/filedata/replicate.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/pkg/controller/filedata/replicate.go b/server/pkg/controller/filedata/replicate.go index 708a654b4f3..c9f99ed964a 100644 --- a/server/pkg/controller/filedata/replicate.go +++ b/server/pkg/controller/filedata/replicate.go @@ -74,7 +74,7 @@ func (c *Controller) tryReplicate() error { "type": row.Type, "size": row.Size, "userID": row.UserID, - }).Errorf("Could not delete file data: %s", err) + }).Errorf("Could not replicate file data: %s", err) return err } else { // If the replication was completed without any errors, we can reset the lock time From 9e06245941b8c408cb9f005020e6e6dbe2405d95 Mon Sep 17 00:00:00 2001 From: Neeraj Gupta <254676+ua741@users.noreply.github.com> Date: Wed, 6 Nov 2024 15:44:59 +0530 Subject: [PATCH 3/4] [server] increse file data replication lockTime --- server/pkg/controller/filedata/replicate.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/pkg/controller/filedata/replicate.go b/server/pkg/controller/filedata/replicate.go index c9f99ed964a..45b67865647 100644 --- a/server/pkg/controller/filedata/replicate.go +++ b/server/pkg/controller/filedata/replicate.go @@ -57,7 +57,7 @@ func (c *Controller) replicate(i int) { } func (c *Controller) tryReplicate() error { - newLockTime := enteTime.MicrosecondsAfterMinutes(60) + newLockTime := enteTime.MicrosecondsAfterMinutes(240) ctx, cancelFun := context.WithTimeout(context.Background(), 20*time.Minute) defer cancelFun() row, err := c.Repo.GetPendingSyncDataAndExtendLock(ctx, newLockTime, false) From 9a683d65c99a907bae8881c58f03a602a6d5f668 Mon Sep 17 00:00:00 2001 From: Neeraj Gupta <254676+ua741@users.noreply.github.com> Date: Wed, 6 Nov 2024 17:27:30 +0530 Subject: [PATCH 4/4] [server] Log userID on passkey auth failure --- server/pkg/api/user.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/server/pkg/api/user.go b/server/pkg/api/user.go index b919572abaa..f0ede26f2fa 100644 --- a/server/pkg/api/user.go +++ b/server/pkg/api/user.go @@ -4,6 +4,8 @@ import ( "database/sql" "errors" "fmt" + "github.com/gin-contrib/requestid" + "github.com/sirupsen/logrus" "net/http" "strconv" "strings" @@ -340,6 +342,10 @@ func (h *UserHandler) FinishPasskeyAuthenticationCeremony(c *gin.Context) { err = h.UserController.PasskeyRepo.FinishAuthentication(&user, c.Request, uuid.MustParse(request.CeremonySessionID)) if err != nil { + reqID := requestid.Get(c) + logrus.WithField("req_id", reqID). + WithField("user_id", userID). + WithError(err).Error("Failed to finish passkey authentication ceremony") handler.Error(c, stacktrace.Propagate(err, "")) return }