posit-dev / posit-dev/shinylive

Potential bug: Uncaught TypeError: Failed to execute 'enqueue' on 'ReadableStreamDefaultController'

Open
#219 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
251
Forks
25
Avg merge
19m
Merged PRs (30d)
2

Description

In a shinylive application that uses r-shinylive I observed the following client error on Chrome (MacOS) when doing a very long running computation that is also quite memory intensive.

Uncaught TypeError: Failed to execute 'enqueue' on 'ReadableStreamDefaultController': Cannot enqueue a chunk into a closed readable stream
    at MessagePort.

The code that produced the error is here

...
  if (msg.body) {
    streamController!.enqueue(filter(msg.body, response!));
  }
  if (!msg.more_body) {
    // All done
    streamController!.close();
    clientPort.close();
  }
...

It seems like it can happen that a streamController gets closed before all remaining messages have been enqueued. I am sure there are multiple ways to address it. I am also happy to contribute a fix of course (e.g. we could stop the event handler in case the streamContoller has been closed - but maybe the root issue is somewhere else). Also sorry for not providing a reproducible example - quite hard to do so, as this error only occasionally appears.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in src/messageporthttp.ts around the enqueue and close calls shown in the report, then trace the MessagePort handler and stream lifecycle. Use a long-running, memory-intensive shinylive application to investigate the intermittent failure; done means the stream completes without attempting to enqueue after it has closed.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
web-dev
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.