Skip to content

Commit 707a67d

Browse files
authored
Merge pull request #6061 from nextcloud/backport/6054/stable29
[stable29] fix(sync): reuse open connection
2 parents b5328e2 + 0ec22ea commit 707a67d

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

cypress/e2e/sync.spec.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ describe('Sync', () => {
111111

112112
it('recovers from a lost and closed connection', () => {
113113
let reconnect = false
114+
// block all requests until the session is closed and reopened
114115
cy.intercept('**/apps/text/session/*/*', (req) => {
115116
if (req.url.includes('close') || req.url.includes('create') || reconnect) {
116117
req.continue()
@@ -125,6 +126,11 @@ describe('Sync', () => {
125126
cy.get('#editor-container .document-status', { timeout: 30000 })
126127
.should('contain', 'Document could not be loaded.')
127128

129+
// Reconnect button works - it closes and reopens the session
130+
cy.get('#editor-container .document-status a.button')
131+
.contains('Reconnect')
132+
.click()
133+
128134
cy.wait('@syncAfterRecovery', { timeout: 60000 })
129135

130136
cy.get('#editor-container .document-status', { timeout: 30000 })

src/services/SyncService.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,12 +104,14 @@ class SyncService {
104104
}
105105

106106
async open({ fileId, initialSession }) {
107-
107+
if (this.#connection && !this.#connection.isClosed) {
108+
// We're already connected.
109+
return
110+
}
108111
const connect = initialSession
109112
? Promise.resolve(new Connection({ data: initialSession }, {}))
110113
: this._api.open({ fileId, baseVersionEtag: this.baseVersionEtag })
111114
.catch(error => this._emitError(error))
112-
113115
this.#connection = await connect
114116
if (!this.#connection) {
115117
// Error was already emitted in connect

0 commit comments

Comments
 (0)