Skip to content

Commit 678cb08

Browse files
committed
fix: Segfault linked to wrong TTL handling (#8)
* fix: Segfault linked to wrong TTL handling Signed-off-by: Matthias Riegler <[email protected]> * chore: remove unnecesary call Signed-off-by: Matthias Riegler <[email protected]> --------- Signed-off-by: Matthias Riegler <[email protected]>
1 parent f6bb9cb commit 678cb08

File tree

2 files changed

+5
-0
lines changed

2 files changed

+5
-0
lines changed

internal/lease/leaseprovider.go

+3
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,7 @@ func (lp *leaseProviderImpl) insert(ctx context.Context, leaseRequest *Request)
307307

308308
// Update the state when it's a whitelisted transition (ACQUIRED -> SUCCESS/FAILURE)
309309
existingStatus := pointer.StringDeref(existing.Status, StatusPending)
310+
// Check if it's a whitelisted transition
310311
leaseRequestStatus := pointer.StringDeref(leaseRequest.Status, StatusPending)
311312
statusMismatch := existingStatus != leaseRequestStatus
312313
allowedTransition := existingStatus == StatusAcquired && (leaseRequestStatus == StatusSuccess || leaseRequestStatus == StatusFailure)
@@ -325,6 +326,8 @@ func (lp *leaseProviderImpl) insert(ctx context.Context, leaseRequest *Request)
325326
return nil, fmt.Errorf("status missmatch for commit %s; expected: `success|failure`, got: `%s`", leaseRequest.HeadSHA, leaseRequestStatus)
326327
}
327328

329+
// Update existing request no matter if it changed or not (it's used for TTL eviction)
330+
lp.updateRequestLastSeenAt(existing)
328331
log.Ctx(ctx).Debug().EmbedObject(existing).Msg("Lease request updated")
329332
}
330333

internal/server/handlers/release.go

+2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"github.com/ankorstore/gh-action-mq-lease-service/internal/lease"
55
"github.com/go-playground/validator/v10"
66
"github.com/gofiber/fiber/v2"
7+
"github.com/rs/zerolog/log"
78
)
89

910
func Release(orchestrator lease.ProviderOrchestrator) func(c *fiber.Ctx) error {
@@ -36,6 +37,7 @@ func Release(orchestrator lease.ProviderOrchestrator) func(c *fiber.Ctx) error {
3637

3738
leaseRequestResponse, err := provider.Release(c.UserContext(), leaseRequest)
3839
if err != nil {
40+
log.Ctx(c.UserContext()).Error().Err(err).Msg("Couldn't release the lock")
3941
return apiError(c, fiber.StatusBadRequest, "Couldn't release the lock", err.Error())
4042
}
4143

0 commit comments

Comments
 (0)