Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

feat(core): add redis lock during insertion of event in event table during initial attempt of outgoing webhook delivery#7579

Open
cookieg13 wants to merge1 commit intomain
base:main
Choose a base branch
Loading
fromeventsLocking

Conversation

cookieg13
Copy link
Contributor

@cookieg13cookieg13 commentedMar 20, 2025
edited
Loading

Type of Change

  • Bugfix
  • New feature
  • Enhancement
  • Refactoring
  • Dependency updates
  • Documentation
  • CI/CD

Description

The current implementation of insertion of an event inevent table does not handle the case where multiple requests with the same idempotent_event_id might be processed concurrently, leading to multiple unique constraint violation errors in the database.

This was reported by a merchant who was facing high volumes of unique constraint violation errors.

NOTE: this unique constraint log error issue is only applicable for theinitial attempt of outgoing webhook delivery, not for retry attempts

Why does this happen?

  1. Multiple requests with the sameidempotent_event_id might reach the database at the same time.
  2. Each request checks for the event, finds nothing (since it’s not committed yet), and proceeds to insert.
  3. The first request succeeds, while the others fail due to the unique constraint on idempotent_event_id.

Solution (Using Redis Lock)
Before querying the database, acquire a lock in Redis for the givenidempotent_event_id.
If there are multiple processes with sameidempotent_event_id only one process will hold the lock, others will leave early.

If a lock is acquired:

  • Check if the event already exists in the database.
  • If it exists, return early
  • Otherwise, insert the event.
  • Once done, release the lock

Additional Changes

  • This PR modifies the API contract
  • This PR modifies the database schema
  • This PR modifies application configuration/environment variables

Motivation and Context

How did you test it?

Checklist

  • I formatted the codecargo +nightly fmt --all
  • I addressed lints thrown bycargo clippy
  • I reviewed the submitted code
  • I added unit tests for my changes where possible

@cookieg13cookieg13 self-assigned thisMar 20, 2025
@cookieg13cookieg13 requested a review froma team as acode ownerMarch 20, 2025 07:28
@semanticdiff-comSemanticDiff.com
Copy link

semanticdiff-combot commentedMar 20, 2025
edited
Loading

Review changes with  SemanticDiff

Changed Files
FileStatus
  crates/router/src/core/webhooks/outgoing.rs  17% smaller
  config/config.example.tomlUnsupported file format
  config/deployments/env_specific.tomlUnsupported file format
  config/deployments/integration_test.tomlUnsupported file format
  config/deployments/production.tomlUnsupported file format
  config/deployments/sandbox.tomlUnsupported file format
  config/development.tomlUnsupported file format
  config/docker_compose.tomlUnsupported file format
  crates/router/src/configs/settings.rs  0% smaller
  crates/router/src/configs/validations.rs  0% smaller
  crates/router/src/core/webhooks/utils.rs  0% smaller
  loadtest/config/development.tomlUnsupported file format

merchant_id.get_string_repr(),
unique_locking_key
);
let redis_lock_expiry_seconds = state.conf().lock_settings.redis_lock_expiry_seconds;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

@jarnura Are we okay with using the same TTL as that used for API locking?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Have a separate locking expiry time

@cookieg13cookieg13force-pushed theeventsLocking branch 4 times, most recently froma511363 to7d21415CompareApril 9, 2025 08:46
@cookieg13cookieg13 requested a review froma team as acode ownerApril 9, 2025 08:46
…uring initial attempt of outgoing webhook delivery
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@jarnurajarnurajarnura left review comments

@SanchithHegdeSanchithHegdeSanchithHegde left review comments

At least 2 approving reviews are required to merge this pull request.

Assignees

@cookieg13cookieg13

Labels
A-coreArea: Core flows
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

3 participants
@cookieg13@jarnura@SanchithHegde

[8]ページ先頭

©2009-2025 Movatter.jp