Skip to content

EventStreamReader should limit the size of an event #1597

Closed

Description

@jlouvel

Problem

EventStreamReader (org.restlet.representation) has no limit on the size of a line or an event. It reads lines with BufferedReader.readLine(), and appends data: and comment lines to StringBuilders until a blank line ends the event.

A server that sends a very long line, or many data: lines with no blank line, makes the client buffer the whole thing in memory. A slow or hostile server can exhaust the client's heap with a single event.

Why it matters

SSE clients usually consume streams from servers they don't control, such as MCP servers and GraphQL subscriptions over graphql-sse. The GraphQL extension (#1581, #1592) works around this today with a byte budget per event on the input stream, which is approximate (one 8 KiB read-ahead margin) and has to be repeated by every SSE client.

Proposed direction

  • Add a maximum event size to EventStreamReader, counting the data and comment text of the pending event and the current line. For example, use a constructor argument or a setter, with a generous default (e.g. 1 MiB) or "unlimited" to keep current behavior.
  • When the limit is exceeded, throw an IOException from readEvent() and stop reading, rather than truncating the event.
  • Read lines with a bounded reader so that a single line can't grow past the limit before it is checked.

Related

Activity

  1. added 4 commits that reference this issue on Nov 1, 2026
    2e6877e
    8a06cec
    a87565d
    2630dba
  2. jlouvel commented on Nov 2, 2026

    @jlouvel
    CollaboratorAuthor

    Fixed by #1604, merged into 3.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions