Skip to content

fix(decomposedfs): [OCISDEV-943] return WriteResult with SpaceOwner f… - #615

Merged
LarsJurgensen merged 1 commit into
mainfrom
fix/OCISDEV-943-write-result-space-owner
Jun 12, 2026
Merged

LarsJurgensen merged 1 commit into
mainfrom
fix/OCISDEV-943-write-result-space-owner

Conversation

@LarsJurgensen

Copy link
Copy Markdown

The goal is to move storagespace.ContextSendSpaceOwnerID(ctx, rn.SpaceOwnerOrManager(ctx)) out of drivers, to make events driver independent & drivers don't implement event specific logic. Instead, this channel is populated in the storageprovider now.

2 additional changes:
The channel had a race condition, so it's not guarenteed the ownerId got set. With refactoring, this race condition is happening more often. Race condition got fixed by using a buffered channel instead & making the sending blocking:
sendOwnerChan := make(chan *user.UserId, 1)

select {
case ch <- id:
default:
}

Additionally, conversion.go had a bug, that FileLocked & FileUnlocked event conversion did not pass the ownerId.

@kw-security

kw-security commented Jun 3, 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)
✅ Code Security 0 0 0 0 0 issues

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

@LarsJurgensen
LarsJurgensen force-pushed the fix/OCISDEV-943-write-result-space-owner branch from b7cd836 to 77d16f2 Compare June 3, 2026 11:09
Comment thread pkg/storage/fs/s3/s3.go Resolved
Comment thread pkg/storage/utils/localfs/localfs.go Resolved

@mklos-kw mklos-kw left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpick, good overall

Comment thread pkg/storage/storage.go Resolved
Comment thread pkg/storage/storage.go Resolved
Comment thread pkg/storage/storage.go Resolved
@jvillafanez

Copy link
Copy Markdown
Member

The channel had a race condition, so it's not guarenteed the ownerId got set. With refactoring, this race condition is happening more often. Race condition got fixed by using a buffered channel instead & making the sending blocking:
sendOwnerChan := make(chan *user.UserId, 1)

I think you got it wrong. The user will eventually be sent through the channel, and I'd expect the receiver to block until it receives the user (because it's a blocking channel).
The problem is that, if a second receiver wants to get the user, someone must send it again through the channel or the receiver will wait indefinitely.

With the PR, the sender won't block, and it's possible that it won't send the user if the channel is full. This seems riskier than the previous solution.

I have no idea why it's implemented this way, but I feel there is something wrong and there should be a better solution.

@LarsJurgensen

Copy link
Copy Markdown
Author

The channel had a race condition, so it's not guarenteed the ownerId got set. With refactoring, this race condition is happening more often. Race condition got fixed by using a buffered channel instead & making the sending blocking:
sendOwnerChan := make(chan *user.UserId, 1)

I think you got it wrong. The user will eventually be sent through the channel, and I'd expect the receiver to block until it receives the user (because it's a blocking channel). The problem is that, if a second receiver wants to get the user, someone must send it again through the channel or the receiver will wait indefinitely.

With the PR, the sender won't block, and it's possible that it won't send the user if the channel is full. This seems riskier than the previous solution.

I have no idea why it's implemented this way, but I feel there is something wrong and there should be a better solution.

The channel had a race condition, so it's not guarenteed the ownerId got set. With refactoring, this race condition is happening more often. Race condition got fixed by using a buffered channel instead & making the sending blocking:
sendOwnerChan := make(chan *user.UserId, 1)

I think you got it wrong. The user will eventually be sent through the channel, and I'd expect the receiver to block until it receives the user (because it's a blocking channel). The problem is that, if a second receiver wants to get the user, someone must send it again through the channel or the receiver will wait indefinitely.

With the PR, the sender won't block, and it's possible that it won't send the user if the channel is full. This seems riskier than the previous solution.

I have no idea why it's implemented this way, but I feel there is something wrong and there should be a better solution.

@jvillafanez
What do you think about moving away from channel here and just use ctx with a slot instead? Writing the value into context directly doesn't work, cause we have to pass the value from callee to caller not vice versa. But with a slot it would work. Do you see any disadvantages of that over using a channel? Similar to context.go in this MR: https://github.com/owncloud/reva/pull/617/changes#diff-9a8ed0aa3871fa1e717e0d26de006deccce32f77bb6d768390bc21e485658ea0

@LarsJurgensen

LarsJurgensen commented Jun 9, 2026 •

Copy link
Copy Markdown
Author

The channel had a race condition, so it's not guarenteed the ownerId got set. With refactoring, this race condition is happening more often. Race condition got fixed by using a buffered channel instead & making the sending blocking:
sendOwnerChan := make(chan *user.UserId, 1)

I think you got it wrong. The user will eventually be sent through the channel, and I'd expect the receiver to block until it receives the user (because it's a blocking channel). The problem is that, if a second receiver wants to get the user, someone must send it again through the channel or the receiver will wait indefinitely.

With the PR, the sender won't block, and it's possible that it won't send the user if the channel is full. This seems riskier than the previous solution.

I have no idea why it's implemented this way, but I feel there is something wrong and there should be a better solution.

The channel had a race condition, so it's not guarenteed the ownerId got set. With refactoring, this race condition is happening more often. Race condition got fixed by using a buffered channel instead & making the sending blocking:
sendOwnerChan := make(chan *user.UserId, 1)

I think you got it wrong. The user will eventually be sent through the channel, and I'd expect the receiver to block until it receives the user (because it's a blocking channel). The problem is that, if a second receiver wants to get the user, someone must send it again through the channel or the receiver will wait indefinitely.

With the PR, the sender won't block, and it's possible that it won't send the user if the channel is full. This seems riskier than the previous solution.

I have no idea why it's implemented this way, but I feel there is something wrong and there should be a better solution.

@jvillafanez
You wrote "The user will eventually be sent through the channel, and I'd expect the receiver to block until it receives the user". I don't think this is correct. The reader is implemented in events.go like this:

 select {
          case ownerID = <-sendOwnerChan:
          default:
 }

If I understand it correctly, this is a non-blocking read, because of the default case. So it tries to read the value from the channel, but if nothing was written yet, it just continues. This mean 1) it's a race condition, because if the goroutine with the writer has not been started yet, nothing will be read. I did see this behavior in practices while debugging, the spaceOwnerId was not reliably set.
With my PR 1) the channel is buffered and 2) the write is not in a goroutine anymore. Because the write is not in the goroutine, the write is guarenteed to happen before the read and there is no race condition anymore. I have default cases for both reader & writer, but not because this is a valid scenario, but just to make sure it does not break something, when code is changed in the future. In practice, there should never be 2 writers. Let me know what you think.

I'm confident that the old channel implementation did not work correctly & did test that the current implementation fixes it. However, we can still discuss alternatives, e.g. having a slot instead of a channel

@jvillafanez

Copy link
Copy Markdown
Member

If I understand it correctly, this is a non-blocking read, because of the default case. So it tries to read the value from the channel, but if nothing was written yet, it just continues.

Yes, you're right. I didn't see that code piece.

What do you think about moving away from channel here and just use ctx with a slot instead? Writing the value into context directly doesn't work, cause we have to pass the value from callee to caller not vice versa.

It should be possible to set a pointer in the context. The callee could modify the pointed value without changing the reference in the context, so the caller would see the change.
Of course there are risks because anyone could modify the value for everyone in the context, but as long as it's documented and we're careful, the approach seems cleaner.

You can check https://github.com/owncloud/reva/pull/619/changes#diff-3704079fb17387ef8fb9459d686e0de5c11acdf6260aef4f93b92207ce080d95 as an example.

I think that's more or less what you want to do. It needs to be easy and very transparent to use, basically a "Get" and a "Set" (with a big warning). From an usability point of view, I just want to know that setting the user might change the user in parent contexts (because we're using a pointer).

@LarsJurgensen

LarsJurgensen commented Jun 9, 2026 •

Copy link
Copy Markdown
Author

It should be possible to set a pointer in the context. The callee could modify the pointed value without changing the reference in the context, so the caller would see the change.

@jvillafanez
Updated this, to use slot pointer instead of channel. Following the same pattern as these MRs:
#617
#616

@jvillafanez

Copy link
Copy Markdown
Member

Some additional things:

  • I'd rename the SpaceOwnerIDSlot to SpaceOwnerInfo, so we can include both the space information and the owner information.
    • Technically, anyone could get the space owner almost anywhere in the request; it seems weird we don't know which space he's owning though.
    • We could include additional validation if you try to use the contextual space owner outside of the marked space.
  • Include a ContextGetSpaceOwner. If you just want to get the information, you shouldn't need to write anything.
ownerSlot := &storagespace.SpaceOwnerIDSlot{}
ctx = storagespace.ContextRegisterSpaceOwnerIDSlot(ctx, ownerSlot)
.......
ownerID := ownerSlot.OwnerID

The problem I see there is that it set up a dangerous precedent: if I need to get the space owner somewhere else, I'll be more inclined to copy this existing code, which could break things because I'll overwrite any existing space owner in the context.

Using a ContextGetSpaceOwner(ctx context.Context) *SpaceOwnerIDSlot {...} is easier, and we have a better control on what to return if there is no space owner set; return nil, or an error.
Basically, make clear that there is a function to write the space owner in the context, and another function to retrieve that information.

jvillafanez
jvillafanez previously approved these changes Jun 10, 2026
@jvillafanez

Copy link
Copy Markdown
Member

Nothing more to add from me 👍

…rom write operations

test(decomposedfs): [OCISDEV-943] verify WriteResult SpaceOwner in integration tests

remove licence header

review comments

review comment

review comments

review comments

review comments

review comments

review comments

revert setting owner in Lock events & var rename

make event usage consistent

Make move event usage consistent to other events

add cephfs error handling
@LarsJurgensen
LarsJurgensen force-pushed the fix/OCISDEV-943-write-result-space-owner branch from 270fa40 to 11d67f7 Compare June 12, 2026 07:19
@LarsJurgensen
LarsJurgensen merged commit 414bbe6 into main Jun 12, 2026
14 checks passed
@LarsJurgensen
LarsJurgensen deleted the fix/OCISDEV-943-write-result-space-owner branch June 12, 2026 07:43
dragonchaser pushed a commit to opencloud-eu/reva that referenced this pull request Nov 11, 2026
CreateDir, TouchFile, RestoreRevision, RestoreRecycleItem, SetLock and
Unlock now return a typed result with the space owner instead of
pushing it through a channel registered in the context. The events
middleware registers a slot, the storageprovider writes the owner from
the result into it, and the middleware reads it after the handler
returned. That replaces the goroutine + channel dance, which could drop
the owner when the select ran before the goroutine sent it.

The move result slot follows the same pattern now and the middleware
no longer builds an ItemMoved event without a move result.

Our trashbin interface differs from upstream (it is space id based and
returns the restored node), so Decomposedfs.RestoreRecycleItem builds
the result from the restored node instead of the trashbin returning it.
The cephfs, s3 and cbox eoswrapper drivers do not exist here.

backport of owncloud#615

Assisted-by: Claude Code:claude-opus-5-5
Signed-off-by: Jörn Friedrich Dreyer <[email protected]>
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.

6 participants