Skip to content

Post E2EE worker errors as plain objects - #2294

Merged
lukasIO merged 3 commits into
mainfrom
fix-e2ee-worker-error-clone
Nov 23, 2026
Merged

lukasIO merged 3 commits into
mainfrom
fix-e2ee-worker-error-clone

Conversation

@lukasIO

@lukasIO lukasIO commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

Safari before version 17 cannot structured-clone an Error object. The E2EE worker posts an Error to the page for each cryptor error. On these Safari versions the postMessage call throws a DataCloneError, and the page never receives the EncryptionError event.

The worker now posts the name and the message as a plain object. E2EEManager builds the Error from it. The same applies to the errors of data encryption and decryption requests.

🤖 Generated with Claude Code

Safari before version 17 cannot structured-clone an Error object. The
postMessage call in the worker threw a DataCloneError, and the page
never received the encryption error.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@github-actions

Copy link
Copy Markdown
Contributor

This PR bumps

  • livekit-client: patch

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Devin Review found 1 potential issue.

2 flags not posted on this PR by your GitHub settings — view them in Devin Review. (Configure)

Devin Review

Comment thread src/e2ee/worker/e2ee.worker.ts Outdated
Comment on lines +164 to +167
error:
error instanceof Error
? { name: error.name, message: error.message }
: { name: 'Error', message: String(error) },

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔴 Failed decryption stalls incoming data

On Safari 16, workerLogger.error posts the raw error for the first decryption failure when error logging is enabled. That post throws before the worker replies. handleDataMessage keeps its lock while waiting, so later packets never run.

Learn more

The worker must send a reply with the request ID so handleEncryptedData can settle its pending promise. DataCryptor.decrypt throws a native Error when the required key is unavailable. The first failure for that participant reaches the error log, and the worker logger posts the entire context, including that native error. Safari 16 throws a DataCloneError there before the new plain-object reply is sent. Incoming packets share a lock that handleDataMessage releases only after the pending decryption settles.

Example: A Safari 16 participant with default logging receives an encrypted packet before the matching key is installed. That packet never finishes processing, and installing the key does not free the lock for later packets.

Recommended fix: Serialize the caught error once before logging, then use that plain object in both the log context and the UUID reply. Add a worker-side test with a postMessage stub that rejects native errors and verify that the first failed decryption still sends its UUID reply.

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

@github-actions

github-actions Bot commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

size-limit report 📦

Path Size
dist/livekit-client.esm.mjs 118.56 KB (-0.02% 🔽)
dist/livekit-client.umd.js 128.12 KB (+0.12% 🔺)
dist/core/core.mjs 79.84 KB (0%)

Comment thread src/e2ee/worker/e2ee.worker.ts Outdated
error:
error instanceof Error
? { name: error.name, message: error.message }
: { name: 'Error', message: String(error) },

@1egoman 1egoman Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: It might also be worth capturing error.stack here too, so errors can be traced across the worker boundary? Something like:

// e2ee.worker.ts (encrypt/decrypt request path)
error instanceof Error
  ? { name: error.name, message: error.message, stack: error.stack }
  : { name: 'Error', message: String(error) },

// E2eeManager.ts
const error = new Error(data.error.message);
error.name = data.error.name;
if (data.error.stack) {
  error.stack = data.error.stack;
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good idea!

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed in 7f08713

lukasIO and others added 2 commits November 23, 2026 08:43
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
The worker forwards each log call to the page with postMessage. A raw
Error in the log context made that call throw on Safari before version
17. In the data decryption path the log call runs before the reply, so
the pending request never settled.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@lukasIO
lukasIO merged commit 7661cb2 into main Nov 23, 2026
8 checks passed
@lukasIO
lukasIO deleted the fix-e2ee-worker-error-clone branch November 23, 2026 07:46
1egoman added a commit that referenced this pull request Nov 23, 2026
The test added in #2294 declared its own `replies`, which shadows the
suite's, and its afterEach resets postMessage to a no-op, which would
stop the barrier from ever seeing its echo. Install the recorder before
each test and let the new test push into the shared replies.
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.

2 participants