Skip to content

fix: [stable-8.0][OCISDEV-1685] remove stale group shares in the share manager - #13460

Draft
2403905 wants to merge 7 commits into
stable-8.0from
fix/stable-8.0-OCISDEV-1685
Draft

2403905 wants to merge 7 commits into
stable-8.0from
fix/stable-8.0-OCISDEV-1685

Conversation

@2403905

@2403905 2403905 commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

Description

Bump reva to v2.0.0-20261117225436-38d3324cefd7 (38d3324ce), the head of owncloud/reva#813.

The jsoncs3 share manager uploaded the received.json file of a user again on each listing of the received shares when the user had a stale group share.
A stale group share is a share ID in the group cache that has no share.
The removal did not change the file, and the stale ID stayed, so this repeated on each listing.
In production, this causes a large volume of share not found. cleaning up warnings and one full document upload per stale share for each listing.

Changes in reva

Stale share cleanup

  • The share manager removes a stale group share from the group cache. When the download of the space file gets NotFound, the share manager checks the file again with a Stat, because a NotFound can be temporary. A second NotFound proves that the file is missing. Thus the cleanup also removes an entry from a failed first share in a space, which has no space file.
  • The cleanup reads each share from the same copy of the space file as the etag. Before, a parallel listing that got a temporary NotFound could empty the cache between two reads. Then all shares looked stale, and the cleanup removed valid shares for the whole group.
  • The cleanup removes a stale entry only after a grace period of 5 minutes (Manager.StaleShareGracePeriod). An older version writes the grantee entry and the share at the same time. During a rolling upgrade, a listing can find the grantee entry before the share is on storage. Before, the listing removed this entry, and no group member saw the share. The rule applies to user entries and to group entries. A listing that finds the share again restarts the grace period, so two short losses do not add up to one long loss.
  • Each pod counts the grace period itself. A pod remembers a stale entry for 1 hour after the last listing that found it. It looks for the entries to forget at most once a minute. Before, the pod forgot the entry 50 minutes after it first found it. With many pods, one pod can find the same stale entry less often than that. That pod then started the grace period again on each listing, and the stale entry stayed. When the removal of a stale entry fails, the next listing tries the removal again at once. The pod forgets the entry only after the removal. Before, a failed removal started a new grace period.
  • A Remove does not upload a file when the share is not in it.
  • After a failed upload that is not a CAS conflict, Add and RemoveMany in each cache drop the cached document. The next call then reads the file again. Before, the memory state stayed different from the file, because the etag did not change and a sync got NotModified. After a failed Remove, a retry found nothing to remove, did not upload, and reported success. The share stayed in the file. After a failed Add, the pod showed an entry that was not in the file. For example, a client got an error when it accepted a share, but this pod showed the share as accepted.
  • A listing of the created shares reads each share from the same copy of the space file. Before, a parallel sync with a temporary NotFound could reset the cache between two reads, and the creator saw only some shares of the space.
  • The cleanup sends only the IDs that are in the received.json of the user to the user cache. Before, it sent the stale group IDs too, and the user cache downloaded the file again to find nothing to remove.

Share and unshare

  • Share writes the share before the grantee entry. When a write fails, it removes the entries that it wrote, also the grantee entry. Before, the failed write kept the share ID in memory, and the next write of the grantee document uploaded it.
  • The rollback runs with a context that the request cancellation does not stop, with a timeout of 30 seconds for each removal. Before, the three removals shared one timeout, and a slow first removal made the other removals fail. The rollback removes the share and the entry of the creator at the same time, after the grantee entry. Thus a failed share waits for at most two timeouts, not three. Before, a cancelled request made each rollback write fail, the share stayed, and a new share failed with AlreadyExists.
  • An unshare and an update of a share read the space file again when the share is not in memory. Before, a listing that got a temporary NotFound left an empty copy of the space in memory. An unshare then did not remove the share from the file, but it reported success. An update returned NotFound for a share that existed.
  • An update of a share reads the share under the space lock, changes a copy and uploads it with a CAS retry. Before, a parallel failed upload in the same space could remove the space from memory. The update then reported success, but it did not write the change. The update also changed the cached share in place, and a retry after a CAS conflict lost the expiration.
  • An update returns NotFound for a share that a parallel unshare removed. Before, the update could write the removed share again.
  • An unshare removes the share also when the grantee entry cannot be removed, and it reports success. The gateway removes the storage grant in this case too. Before, the client got an error for a share that was gone, no ShareRemoved event went out, and a retry got NotFound. An unshare still fails when the share itself cannot be removed.

Batch removal

  • The share manager removes many shares together, with one upload for each document. A purge of a space with 20 group shares did 41 uploads and now does 3. A listing that finds 20 expired shares did 60 uploads and now does 3.
  • A listing removes the expired shares of all spaces together, after all workers stop.
  • MaxConcurrency (SHARING_USER_JSONCS3_MAX_CONCURRENCY) limits the parallel removals. The limit is at least 3. Before the batched removal, the removal of one share updated its 3 documents in parallel. With a limit of 1, an unshare needed one more round trip to the storage. When reva gets no value, the limit is 10. Before, a purge of a space with many grantees started one parallel write for each document.
  • The share manager publishes one ShareExpired event for each expired share. providercache.Cache.RemoveMany returns the IDs that its CAS upload removed, so only one caller wins, also across pods. Before, each listing that found the expired share published an event, also when the removal failed.
  • sharecache.Cache.RemoveMany deletes a space entry when it removes the last share of the space. Before, each listing read the space file of a purged space again.

Cleanup of orphaned shares

  • The share cleanup of the ocis shares commands removes all orphaned shares together, with one upload for each document. 20 orphaned shares in one space did 60 uploads and now do 3.
  • A Stat error no longer stops the cleanup with a panic. The cleanup logs the error and checks the next share.
  • When the cleanup cannot get a gateway client, it logs an error and stops. Before, it stopped with a panic.

Other

  • After a space delete, the share manager logs the errors of the share cleanup. Before, it sent them to a disabled logger.
  • Each log line of ListReceivedShares and of the listing by resource ID has the fields of one share only. Before, the listing added the fields of each share to the same logger. A later line had the fields of all earlier shares, and a log search found the wrong share.
  • gofmt formats the jsoncs3 files.
  • sharecache.Cache.Remove no longer panics when the user or group has no entry for the space of the share, or when the share ID has no delimiter (OCISDEV-1675). Before, the panic stopped the sharing service, also in an unshare and in the cleanup of orphaned shares.

Changes in ocis

  • The default of SHARING_USER_JSONCS3_MAX_CONCURRENCY does not change and is 1. The value sets the number of listing workers and the limit of parallel removals. More listing workers make small machines slower.
  • The description of SHARING_USER_JSONCS3_MAX_CONCURRENCY now says that the removal of shares always uses at least 3 parallel go-routines.

Vendor diff

Against the reva pin of stable-8.0 (48aa66c6d, #13446), this bump adds only the commits of owncloud/reva#813. They change only these files:

  • pkg/share/manager/jsoncs3/jsoncs3.go
  • pkg/share/manager/jsoncs3/providercache/providercache.go
  • pkg/share/manager/jsoncs3/receivedsharecache/receivedsharecache.go
  • pkg/share/manager/jsoncs3/sharecache/sharecache.go

Changelog

changelog/unreleased/bugfix-jsoncs3-stale-group-shares.md

Checks

  • go mod vendor with GOWORK=off gives no change. go mod verify passes.
  • The ocis ocis, sharing, storage-users, storage-shares, frontend and graph packages build from vendor/.
  • The reva tests for pkg/share/manager/jsoncs3/... pass with -race. Each new regression test failed before its fix.
  • The four vendored jsoncs3 files are the same as reva 38d3324ce.

Known issues

  • Manager.initialize in reva reads initialized without the lock. The race detector reports it when parallel listings start on a new manager. This race also exists on stable-8.0. It needs a separate fix.
  • Manager.Load in reva, which the share migration uses, calls UserReceivedStates.Add with only the space ID as the key. The other code uses storageid:spaceid. Migrated user shares can thus get the wrong key. A code review found this. No test confirms it yet. It also exists on stable-8.0 and needs a separate ticket.

Status

Draft. It depends on owncloud/reva#813. When that pull request is merged, the reva version must point to the merge commit on reva stable-8.0.

Reva stable-8.0 also has e140a3899 (owncloud/reva#812, OCISDEV-1140), which is not in the current pin. The re-pin to the merge commit adds it, and it then needs its own changelog entry in ocis.

🤖 Generated with Claude Code

@kw-security

kw-security commented Nov 13, 2026 •

Copy link
Copy Markdown

✅ Snyk checks have passed. No issues have been found so far.

Status Scan Engine Critical High Medium Low Total (0)
✅ Open Source Security 0 0 0 0 0 issues
✅ Licenses 0 0 0 0 0 issues
✅ Code Security 0 0 0 0 0 issues

💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse.

@2403905
2403905 requested a review from a team November 13, 2026 09:08
@2403905
2403905 force-pushed the fix/stable-8.0-OCISDEV-1685 branch 4 times, most recently from 29b954c to 63b62a9 Compare November 17, 2026 18:01
2403905 and others added 7 commits November 18, 2026 17:21
…e manager

Bump reva to a31eb537b, the head of owncloud/reva#813.

A stale group share is a share ID in the group cache that has no share. On
each listing of the received shares, the jsoncs3 share manager uploaded the
received.json file of the user again with the same content, and the stale ID
stayed.

The new reva:
- removes stale group shares from the group cache, only when it read the
  space file or a Stat proved that the file is missing
- removes a stale entry only after a grace period of 5 minutes, and forgets
  a stale entry 1 hour after the last listing that found it
- does not upload a file when a Remove changes nothing, and reads the file
  again after a failed Add or Remove upload
- does not panic in sharecache Remove when the space entry is missing
- writes a share before the grantee entry, and rolls back after a failure
- removes the share in an unshare also when the grantee entry fails
- removes many shares with one upload for each document, with at most
  MaxConcurrency removals in parallel
- publishes one ShareExpired event for each expired share
- logs the share cleanup errors after a space delete

The default of SHARING_USER_JSONCS3_MAX_CONCURRENCY changes from 1 to 5.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Roman Perekhod <2403905@gmail.com>
Pin reva to ea52e6ec5. The new reva commit fixes these problems:
- UpdateShare can report success for a change that it did not write.
- UpdateShare can write a share again after a parallel unshare.
- A listing of the created shares can miss some shares of a space.
- A failed removal of a stale share starts a new grace period.

Set the default of SHARING_USER_JSONCS3_MAX_CONCURRENCY back to 1. The
value also sets the workers of each listing. Commit a35618a set it
to 1 because more workers make small machines slower.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Roman Perekhod <2403905@gmail.com>
…n the cleanup

Pin reva to c000cf743. The new reva commit fixes these problems in the
share cleanup of the ocis shares commands:
- The cleanup removed the orphaned shares one at a time. 20 orphaned
  shares in one space did 60 uploads. They now do 3 uploads.
- A Stat error stopped the cleanup with a panic.
- A failed gateway selection stopped the cleanup with a panic.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Roman Perekhod <2403905@gmail.com>
Pin reva to e3ee7a4ed. The share removals now use a limit of at least
3, also when SHARING_USER_JSONCS3_MAX_CONCURRENCY is 1. With a limit of
1, an unshare needed one more round trip to the storage. The default of
the setting does not change and is 1.

Describe the floor in the setting description and in the changelog.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Roman Perekhod <2403905@gmail.com>
… memory

Pin reva to 38d3324ce. The new reva commit fixes these problems in the
provider cache of the jsoncs3 share manager:
- An unshare reported success, but the share stayed in the space file.
- An update returned NotFound for a share that existed.

Both occurred after a listing got a temporary NotFound and left an empty
copy of the space in memory. A Remove and an Update now read the space
file again when the share is not in memory.

go mod tidy also removes the go.sum lines of older reva pins.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Roman Perekhod <2403905@gmail.com>
…00f664a

The new reva commit joins 5 reva commits. The code is the same as in
the reva commit 38d3324ce. Only the module version changes.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Signed-off-by: Roman Perekhod <2403905@gmail.com>
The new reva commit keeps a map in a purged provider space.
Before, an Add to the purged space on the same pod panicked.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@2403905
2403905 force-pushed the fix/stable-8.0-OCISDEV-1685 branch from 113b3e0 to ac86cad Compare November 18, 2026 16:22

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants