Skip to content

fix: crash in checkMessageQueue due to sessionId/index key mismatch#215

Open
dionisos2 wants to merge 2 commits into
OokTech:mainfrom
dionisos2:main
Open

fix: crash in checkMessageQueue due to sessionId/index key mismatch#215
dionisos2 wants to merge 2 commits into
OokTech:mainfrom
dionisos2:main

Conversation

@dionisos2

Copy link
Copy Markdown

Titre :
fix: crash in checkMessageQueue due to sessionId/index key mismatch (1.7.7)

Description :

Bug

In 1.7.7, sendMessage was updated to key messageData.ack by
connection.sessionId (a string like "planning123456") instead of
connection.index (a number). However, checkMessageQueue and
_sendMessage still used item.socket.index (numeric), causing a
TypeError: Cannot read property 'received' of undefined after 500ms
whenever the server had unacknowledged messages in the queue.

This crashed the active WebSocket connections, which manifested as the
sync button turning red when typing quickly in a text field.

Fixes (SharedFunctions.js)

  • checkMessageQueue: replace item.socket.index with item.sessionId
    and add a null guard
  • _sendMessage: add null guard on messageData.ack[index] before access
  • handleAck (server side): use data.sessionId as source_connection
    fallback so browser acks are properly matched to their queue entry

How it was found

The bug was reproduced and diagnosed using Claude Code.

In 1.7.7, sendMessage switched to keying messageData.ack by
connection.sessionId (string) instead of connection.index (number),
but checkMessageQueue and _sendMessage still used item.socket.index
(numeric), causing a TypeError on undefined when trying to resend
unacked messages after 500ms. This crashed the WebSocket connection.

Three fixes:
- checkMessageQueue: use item.sessionId instead of item.socket.index,
  with null guard
- _sendMessage: add null guard on messageData.ack[index] before access
- handleAck (server): use data.sessionId as source_connection fallback
  so browser acks are properly matched to their queue entry

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@dionisos2 dionisos2 mentioned this pull request Apr 26, 2026
10 tasks
@dionisos2

Copy link
Copy Markdown
Author

Sorry, I thought it worked correctly but there is a problem with the last version of tiddlywiki, I will try to fix it.

Widget.prototype.addEventListener silently ignores {once:true}, causing
handle-ack/loaded-tiddler/skinny-tiddlers listeners to accumulate across
saves. Replaced all 8 occurrences with explicit named-listener +
removeEventListener pattern so each listener self-removes on first call.

Also fix SendToBrowsers in ServerSide.js to compare connection.sessionId
instead of connection index against excludeConnection, preventing the
originating browser from receiving its own save echoed back.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@dionisos2

Copy link
Copy Markdown
Author

This seems to work now.

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.

1 participant