Skip to content

Commit

Permalink
Merge pull request #3891 from nextcloud/backport/stable26/3890-load-f…
Browse files Browse the repository at this point in the history
…resh-session

[stable26] fix: load fresh session if none are remaining
  • Loading branch information
juliusknorr authored Mar 6, 2023
2 parents d85ac88 + 7e47b82 commit d79cdaf
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 3 deletions.
11 changes: 11 additions & 0 deletions cypress/e2e/SessionApi.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -349,5 +349,16 @@ describe('The session Api', function() {
})
})

// Failed with a probability of ~ 50% initially
it('ignores steps stored after close cleaned up', function() {
cy.pushAndClose({ connection, steps: [messages.update], version })
cy.createTextSession(undefined, { filePath: '', shareToken })
.then(con => {
connection = con
})
.its('state.documentSource')
.should('eql', '## Hello world\n')
})

})
})
11 changes: 11 additions & 0 deletions cypress/support/sessions.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,14 @@ Cypress.Commands.add('syncSteps', (connection, options = { version: 0 }) => {
return connection.sync(options)
.then(response => response.data)
})

// Used to test for race conditions between the last push and the close request
Cypress.Commands.add('pushAndClose', ({ connection, steps, version, awareness = '' }) => {
cy.log('Race between push and close')
.then(() => {
const push = connection.push({ steps, version, awareness })
.catch(e => e) // handle 403 gracefully
const close = connection.close()
return Promise.all([push, close])
})
})
6 changes: 3 additions & 3 deletions lib/Service/ApiService.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,12 +113,12 @@ public function create($fileId = null, $filePath = null, $token = null, $guestNa
$readOnly = $this->documentService->isReadOnly($file, $token);

$this->sessionService->removeInactiveSessions($file->getId());
$activeSessions = $this->sessionService->getActiveSessions($file->getId());
$remainingSessions = $this->sessionService->getAllSessions($file->getId());
$freshSession = false;
if ($forceRecreate || count($activeSessions) === 0) {
if ($forceRecreate || count($remainingSessions) === 0) {
$freshSession = true;
try {
$this->documentService->resetDocument($file->getId(), $forceRecreate);
$freshSession = true;
} catch (DocumentHasUnsavedChangesException $e) {
}
}
Expand Down

0 comments on commit d79cdaf

Please sign in to comment.