-
Notifications
You must be signed in to change notification settings - Fork 156
fix:race condition in db tracking module #498
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR attempts to fix a race condition in the DbTrackingModule where concurrent tracking events for the same message ID can cause duplicate key violations in the database. The fix wraps the persist method's logic in a synchronized(msg) block to provide mutual exclusion.
Changes:
- Added synchronized block around the database persistence logic in DbTrackingModule.persist() method
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Server/src/main/java/org/openas2/processor/msgtracking/DbTrackingModule.java
Outdated
Show resolved
Hide resolved
Server/src/main/java/org/openas2/processor/msgtracking/DbTrackingModule.java
Outdated
Show resolved
Hide resolved
Server/src/main/java/org/openas2/processor/msgtracking/DbTrackingModule.java
Outdated
Show resolved
Hide resolved
Server/src/main/java/org/openas2/processor/msgtracking/DbTrackingModule.java
Outdated
Show resolved
Hide resolved
Server/src/main/java/org/openas2/processor/msgtracking/DbTrackingModule.java
Outdated
Show resolved
Hide resolved
uhurusurfa
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be much simpler to just synchronize the entire method by adding synchronize to the method signature.
Although this blocks all threads even if they are trying to log a different message ID, this is a short term solution until the next major release and the performance cost is the same as the mechanism you have used which uses the concurrent hashmap since it will block all threads as well but adds the cost of managing a concurrent hashmap.
uhurusurfa
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚀 Thanks for the fix
fix #496