Skip to content

fix: limit EventSource event size#5552

Open
mcollina wants to merge 2 commits into
mainfrom
fix/eventsource-max-event-size
Open

fix: limit EventSource event size#5552
mcollina wants to merge 2 commits into
mainfrom
fix/eventsource-max-event-size

Conversation

@mcollina

Copy link
Copy Markdown
Member

This relates to...

N/A

Rationale

EventSource messages should not accumulate data beyond Node.js's maximum string length, while allowing applications to configure a lower limit when needed.

Changes

Features

  • Add an eventSource.maxEventSize dispatcher option.

Bug Fixes

  • Limit accumulated EventSource event data to buffer.kStringMaxLength by default.
  • Close the EventSource connection when the configured limit is exceeded.

Breaking Changes and Deprecations

N/A

Status

Signed-off-by: Matteo Collina <hello@matteocollina.com>
@mcollina
mcollina requested review from KhafraDev and trivikr July 13, 2026 15:20
@codecov-commenter

codecov-commenter commented Jul 13, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.48%. Comparing base (197a83d) to head (df7b4ae).
⚠️ Report is 14 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #5552      +/-   ##
==========================================
+ Coverage   93.44%   93.48%   +0.04%     
==========================================
  Files         110      110              
  Lines       37443    37545     +102     
==========================================
+ Hits        34987    35098     +111     
+ Misses       2456     2447       -9     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@KhafraDev KhafraDev left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'm not as familiar with EventSource so some of these might be wrong, feel free to dismiss as needed

Comment thread lib/web/eventsource/eventsource.js Outdated
eventSourceInitDict = webidl.converters.EventSourceInitDict(eventSourceInitDict, prefix, 'eventSourceInitDict')

this.#dispatcher = eventSourceInitDict.node.dispatcher || eventSourceInitDict.dispatcher
this.#dispatcher = eventSourceInitDict.node.dispatcher || eventSourceInitDict.dispatcher || getGlobalDispatcher()

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

this would make more sense as part of the webidl conversion as a default value

module.exports = {
EventSourceStream
EventSourceStream,
defaultMaxEventSize

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I don't see this being imported anywhere

}

getEventDataSize (event) {
if (event === this.event) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

this should always be true

}

setEventDataSize (event, eventDataSize) {
if (event === this.event) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

same here, we can only ever have 1 event at a time

@metcoder95 metcoder95 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

lgtm

leverage to @KhafraDev comments

Signed-off-by: Matteo Collina <hello@matteocollina.com>
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.

6 participants