eclipse-ee4j / eclipse-ee4j/jersey

Server-sent events incorrectly sent on EOF

Open
#3,312 17 comments 0 reactions 0 assignees View on GitHub
Component: media Incomplete Priority: Major Type: Bug
Dominant language
Java
Stars
730
Forks
382
PR merge metrics
No merged PRs in 30d

Description

EOF is no longer a valid delimiter for a server-sent event; it changed between these specification versions:
[http://www.w3.org/TR/2011/WD-eventsource-20111020/](http://www.w3.org/TR/2011/WD-eventsource-20111020/)
[http://www.w3.org/TR/2011/WD-eventsource-20110310/](http://www.w3.org/TR/2011/WD-eventsource-20110310/)

Jersey version 2.22.1 appears not to respect this, my test is as follows:
1\. Open connection and begin receiving events
2\. Suspend my process for > 10 minutes (TCP socket is closed)
3\. Resume process
An incomplete event is received (data is truncated); I believe this can only be because EOF is considered as a delimtier.

My code is as follows:

```
public void subscribe (String name) {
EventListener listener = new EventListener() {
@Override
public void onEvent(InboundEvent inboundEvent) {
try {
String data = inboundEvent.readData();
JSONObject json = new JSONObject(data);
System.out.println(inboundEvent.getName() + ":" + inboundEvent.getId() + ":" + json.getInt("datomic-t"));
} catch (RuntimeException e) {
System.out.println(e.getMessage());
System.out.println(inboundEvent.getName() + ":" + inboundEvent.getId());
};
}
};
WebTarget target = ClientBuilder.newClient().register(SseFeature.class).target(query);
EventSource source = EventSource.target(target).named(name).build();
source.register(listener);
source.open();
}
```
#### Environment
Windows
#### Affected Versions
[2.22.1]

Contributor guide

Open the contributing guide

Research direction

Start with Jersey's SSE client path, especially EventSource, SseFeature, and InboundEvent, and reproduce the reported Windows scenario using the code in the issue. Compare the observed EOF handling with the linked EventSource specifications; done means a closed socket does not deliver truncated incomplete event data as a valid event.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
api, backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.