Fix WebSocket 4409 error on sync logout

Properly remove the sync streaming subscription before clearing the
API key on logout.
This commit is contained in:
Dan Stillman 2026-03-24 12:04:31 -04:00
parent 322b764091
commit 8167c903f3
2 changed files with 32 additions and 1 deletions

View file

@ -102,6 +102,28 @@ Zotero.Streamer_Module.prototype = {
},
/**
* Remove the API key subscription before the key is deleted
*/
removeSyncSubscription: async function () {
if (!this._subscriptions.has('sync')) {
return;
}
let apiKey = this.apiKey || (await Zotero.Sync.Data.Local.getAPIKey());
if (!apiKey || !this._socket || this._socket.readyState !== this._socket.OPEN) {
this._subscriptions.delete('sync');
return;
}
let data = JSON.stringify({
action: 'deleteSubscriptions',
subscriptions: [{ apiKey }]
});
Zotero.debug("WebSocket message send: " + this._hideAPIKey(data));
this._socket.send(data);
this._subscriptions.delete('sync');
},
_sendSubscriptions: function (topics) {
let data = JSON.stringify({
action: "createSubscriptions",
@ -140,7 +162,14 @@ Zotero.Streamer_Module.prototype = {
}
}
else if (this._subscriptions.has('sync')) {
subscriptionsToRemove.push({ apiKey });
if (apiKey) {
subscriptionsToRemove.push({ apiKey });
}
else {
// API key was cleared -- just remove local tracking.
// The server will clean up on reconnect.
this._subscriptions.delete('sync');
}
}
if (Zotero.Prefs.get('automaticScraperUpdates')) {

View file

@ -1683,6 +1683,8 @@ Zotero.Sync.Runner_Module = function (options = {}) {
this.resetStorageController('zfs');
var apiKey = await Zotero.Sync.Data.Local.getAPIKey();
var client = this.getAPIClient({apiKey});
// Remove streaming subscription before clearing the key
await Zotero.Streamer.removeSyncSubscription();
await Zotero.Sync.Data.Local.setAPIKey();
await client.deleteAPIKey();
}