Skip to content
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

bug: key client_id is not present in table clients #295

Closed
geekbrother opened this issue Jan 25, 2024 · 0 comments · Fixed by #296
Closed

bug: key client_id is not present in table clients #295

geekbrother opened this issue Jan 25, 2024 · 0 comments · Fixed by #296
Assignees
Labels
accepted The issue has been accepted into the project

Comments

@geekbrother
Copy link
Contributor

We have rare database error messages containing the following error:

Store(Database(Database(PgDatabaseError { severity: Error, code: "23503", message: "insert or update on table \"notifications\" violates foreign key constraint \"fk_notifications_client_id\"", detail: Some("Key (client_id)=(...) is not present in table \"clients\"."), hint: None, position: None, where: None, schema: Some("public"), table: Some("notifications"), column: None, data_type: None, constraint: Some("fk_notifications_client_id"), file: Some("ri_triggers.c"), line: Some(2509), routine: Some("ri_ReportViolation") })))

We have a client_id related constraint in the database schema that prevents inserting the record to the notifications table without the related client id.

At this error, we are trying to insert the notification without the corresponding client id in the clients table.

When investigating the issue by connecting to the database and inspecting clients and notifications tables, the inspection reveals that the client with the corresponding id is present in the table for the id that caused the error.

We have two different endpoints for the client creation and the notification publishing. When the client creation calls there is INSERT and DELETE into the clients table.

The constraint error occurs as a race condition when two endpoints call in parallel and in the first we are deleting the client id for that we are inserting the new notification from the other notification endpoint before the new row is inserted.

@geekbrother geekbrother self-assigned this Jan 25, 2024
@arein arein added the accepted The issue has been accepted into the project label Jan 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
accepted The issue has been accepted into the project
Projects
None yet
2 participants