-
Notifications
You must be signed in to change notification settings - Fork 112
Fix: writing during short connection failures #7093
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| /** | ||
| * SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors | ||
| * SPDX-License-Identifier: AGPL-3.0-or-later | ||
| */ | ||
|
|
||
| import { afterEach, expect, test, vi } from 'vitest' | ||
| import { useDelayedFlag } from './useDelayedFlag' | ||
| import { nextTick, ref, watch } from 'vue' | ||
|
|
||
| afterEach(() => { | ||
| vi.useRealTimers() | ||
| }) | ||
|
|
||
| test('useDelayedFlag defaults to provided ref value', () => { | ||
| [true, false].forEach(val => { | ||
| const { delayed } = useDelayedFlag(ref(val)) | ||
| expect(delayed.value).toBe(val) | ||
| }) | ||
| }) | ||
|
|
||
| test('switches slowly to true', async () => { | ||
| vi.useFakeTimers() | ||
| const input = ref(false) | ||
| const { delayed } = useDelayedFlag(input) | ||
| input.value = true | ||
| await nextTick() | ||
| vi.advanceTimersByTime(3000) | ||
| expect(delayed.value).toBe(false) | ||
| vi.advanceTimersByTime(5000) | ||
| expect(delayed.value).toBe(true) | ||
| }) | ||
|
|
||
| test('switches fast to false', async () => { | ||
| vi.useFakeTimers() | ||
| const input = ref(true) | ||
| const { delayed } = useDelayedFlag(input) | ||
| input.value = false | ||
| await nextTick() | ||
| expect(delayed.value).toBe(true) | ||
| vi.advanceTimersByTime(300) | ||
| expect(delayed.value).toBe(false) | ||
| }) | ||
|
|
||
| test('does not flip flop', async () => { | ||
| vi.useFakeTimers() | ||
| const input = ref(false) | ||
| const { delayed } = useDelayedFlag(input) | ||
| const probe = vi.fn() | ||
| watch(delayed, probe) | ||
| input.value = true | ||
| await nextTick() | ||
| vi.advanceTimersByTime(1000) | ||
| input.value = false | ||
| await nextTick() | ||
| vi.advanceTimersByTime(5000) | ||
| expect(delayed.value).toBe(false) | ||
| expect(probe).not.toBeCalled() | ||
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| /** | ||
| * SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors | ||
| * SPDX-License-Identifier: AGPL-3.0-or-later | ||
| */ | ||
|
|
||
| import { ref, watch, type Ref } from 'vue' | ||
|
|
||
| /** | ||
| * Delay the changing of the boolean | ||
| * @param input - ref to react to | ||
| */ | ||
| export function useDelayedFlag(input: Ref<boolean>): { delayed: Ref<boolean> } { | ||
|
|
||
| let timeout: ReturnType<typeof setTimeout> | undefined | ||
| const delayed = ref(input.value) | ||
|
|
||
| watch(input, (val) => { | ||
| if (timeout) { | ||
| clearTimeout(timeout) | ||
| } | ||
| const delay = val ? 5000 : 200 | ||
| timeout = setTimeout(() => { | ||
| delayed.value = val | ||
| }, delay) | ||
|
|
||
| }) | ||
|
|
||
| return { delayed } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why would we still wait 200ms when switching back? Can't we do it instantly?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My idea was to reduce the risk of a flickering state. Basically if the error goes away for a brief moment and comes back right after.
But thinking about it again I cannot see how that would happen within 200 ms. The error will only go away after the
pushrequest - which may be triggered by a successfulsync. So then the nextsyncwill be longer than 200 ms away. So I guess we can save the 200 ms and just remove the flag immediately.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All right, that sounds good the still to keep.