nextcloud / nextcloud/server

[Bug]: `oc_share` table has duplicate rows for the same share

Open
#53,970 6 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

1. to develop 32-feedback bug feature: sharing
Dominant language
PHP
Stars
36.9k
Forks
5.2k
Avg merge
2d 3h
Merged PRs (30d)
713

Description

⚠️ This issue respects the following points: ⚠️
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:

  1. Sharing a file in Talk creates a parent entry with share_type 10 and file_target /{TALK_PLACEHOLDER}/file.md
  2. User access conversation with shared file as last message, filesystem is mounted from conversations request and chat messages request
  3. This creates two entries in DB with share_type 11 and file_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 is share_type 11 and file_target /Talk/file.md, and duplicates are share_type 11 and file_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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.