[PR #75] Avoid ID clashes #145

Open
opened 2026-02-27 10:15:56 +03:00 by kerem · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/matze/wastebin/pull/75
Author: @cgzones
Created: 10/26/2024
Status: 🔄 Open

Base: masterHead: id_clash


📝 Commits (1)

📊 Changes

3 files changed (+60 additions, -43 deletions)

View changed files

📝 crates/wastebin_core/src/db.rs (+57 -37)
📝 crates/wastebin_server/src/handlers/insert/api.rs (+1 -3)
📝 crates/wastebin_server/src/handlers/insert/form.rs (+2 -3)

📄 Description

Currently the the ID for a new paste is randomly generated in the caller of the database insert() function. Then the insert() function tries to insert a new row into the database with that passed ID. There can however already exists a paste in the database with the same ID leading to an insert failure, due to a constraint violation due to the PRIMARY KEY attribute. Checking prior the the INSERT via a SELECT query would open the window for a race condition.

A failure to push a new paste is quite severe, since the user might have spent some some to format the input.

Generate the ID in a loop inside, until the INSERT succeeds.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/matze/wastebin/pull/75 **Author:** [@cgzones](https://github.com/cgzones) **Created:** 10/26/2024 **Status:** 🔄 Open **Base:** `master` ← **Head:** `id_clash` --- ### 📝 Commits (1) - [`4ead289`](https://github.com/matze/wastebin/commit/4ead289d341640d67846fd75aaed68e27a7cd09d) Avoid ID clashes ### 📊 Changes **3 files changed** (+60 additions, -43 deletions) <details> <summary>View changed files</summary> 📝 `crates/wastebin_core/src/db.rs` (+57 -37) 📝 `crates/wastebin_server/src/handlers/insert/api.rs` (+1 -3) 📝 `crates/wastebin_server/src/handlers/insert/form.rs` (+2 -3) </details> ### 📄 Description Currently the the ID for a new paste is randomly generated in the caller of the database insert() function. Then the insert() function tries to insert a new row into the database with that passed ID. There can however already exists a paste in the database with the same ID leading to an insert failure, due to a constraint violation due to the PRIMARY KEY attribute. Checking prior the the INSERT via a SELECT query would open the window for a race condition. A failure to push a new paste is quite severe, since the user might have spent some some to format the input. Generate the ID in a loop inside, until the INSERT succeeds. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/wastebin-matze#145
No description provided.