[Bug]: `oc_share` table has duplicate rows for the same share
Nobody has claimed this yet.
- Dominant language
- PHP
- Stars
- 36.9k
- Forks
- 5.2k
- Avg merge
- 2d 3h
- Merged PRs (30d)
- 713
Description
⚠️ This issue respects the following points: ⚠️
- This is a bug, not a question or a configuration/webserver/proxy issue.
- This issue is not already reported on Github OR Nextcloud Community Forum (I've searched it).
- Nextcloud Server is up to date. See Maintenance and Release Schedule for supported versions.
- I agree to follow Nextcloud's Code of Conduct.
Bug description
There might be a race condition in ShareProvider, where several requests in parallel check if share exists in DB, and create it otherwise. In this case, there could be several new entries created, each with unique id, but all pointing to the same share.
If user tries to modify/leave share, it will modify the first row only, keeping the second intact. That way, you can never get rid of it.
Steps to reproduce
Don't have clear steps, but example behaviour sounds logical:
- Sharing a file in Talk creates a parent entry with
share_type10 andfile_target/{TALK_PLACEHOLDER}/file.md - User access conversation with shared file as last message, filesystem is mounted from conversations request and chat messages request
- This creates two entries in DB with
share_type11 andfile_target/Talk/file.md (best reproducible when PHP debugger was enabled, but also occurs on prod/daily instances)
3.1. Worse case if user at some point changed the attachments folder, so initial entry isshare_type11 andfile_target/Talk/file.md, and duplicates areshare_type11 andfile_target/SomeOtherPath/file.md. Modifications will touch only first occurence of /SomeOtherPath/file.md
Expected behavior
Some sort of transactional lock (to write in DB only once) in place
Nextcloud Server version
master
Operating system
None
PHP engine version
None
Web server
None
Database engine version
None
Is this bug present after an update or on a fresh install?
None
Are you using the Nextcloud Server Encryption module?
None
What user-backends are you using?
- Default user-backend (database)
- LDAP/ Active Directory
- SSO - SAML
- Other
Configuration report
List of activated Apps
Nextcloud Signing status
Nextcloud Logs
Additional info
No response
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by tracing ShareProvider operations that check for an existing share and insert into the oc_share table. Reproduce the parallel-request scenario if possible, then determine how duplicate rows can be prevented transactionally. Done means concurrent creation no longer leaves duplicate entries for the same share, with coverage for the race if the project’s existing tests support it.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- php
- Domain
- backend, database
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Needs clarification
- Newbie friendliness
- 38/100