Skip to content

Commit 8efc4ad

Browse files
committed
abort sse request before closing response
1 parent cf784b0 commit 8efc4ad

File tree

4 files changed

+8
-9
lines changed

4 files changed

+8
-9
lines changed

client/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<groupId>io.split.client</groupId>
77
<artifactId>java-client-parent</artifactId>
8-
<version>4.1.2</version>
8+
<version>4.1.3-rc1</version>
99
</parent>
1010
<artifactId>java-client</artifactId>
1111
<packaging>jar</packaging>

client/src/main/java/io/split/engine/sse/client/SSEClient.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,8 @@
22

33
import com.google.common.base.Strings;
44
import org.apache.hc.client5.http.classic.methods.HttpGet;
5-
import org.apache.hc.client5.http.config.RequestConfig;
65
import org.apache.hc.client5.http.impl.classic.CloseableHttpClient;
76
import org.apache.hc.client5.http.impl.classic.CloseableHttpResponse;
8-
import org.apache.hc.client5.http.impl.classic.HttpClients;
9-
import org.apache.hc.client5.http.impl.io.PoolingHttpClientConnectionManager;
10-
import org.apache.hc.core5.util.Timeout;
117
import org.slf4j.Logger;
128
import org.slf4j.LoggerFactory;
139

@@ -50,6 +46,7 @@ private enum ConnectionState {
5046
private final Function<StatusMessage, Void> _statusCallback;
5147
private final AtomicReference<ConnectionState> _state = new AtomicReference<>(ConnectionState.CLOSED);
5248
private final AtomicReference<CloseableHttpResponse> _ongoingResponse = new AtomicReference<>();
49+
private final AtomicReference<HttpGet> _ongoingRequest = new AtomicReference<>();
5350

5451
public SSEClient(Function<RawEvent, Void> eventCallback,
5552
Function<StatusMessage, Void> statusCallback,
@@ -91,6 +88,7 @@ public synchronized void close() {
9188
if (_state.compareAndSet(ConnectionState.OPEN, ConnectionState.CLOSED)) {
9289
if (_ongoingResponse.get() != null) {
9390
try {
91+
_ongoingRequest.get().abort();
9492
_ongoingResponse.get().close();
9593
} catch (IOException e) {
9694
_log.debug(String.format("Error closing SSEClient: %s", e.getMessage()));
@@ -145,10 +143,11 @@ private void connectAndLoop(URI uri, CountDownLatch signal) {
145143
}
146144

147145
private boolean establishConnection(URI uri, CountDownLatch signal) {
148-
HttpGet request = new HttpGet(uri);
146+
147+
_ongoingRequest.set(new HttpGet(uri));
149148

150149
try {
151-
_ongoingResponse.set(_client.execute(request));
150+
_ongoingResponse.set(_client.execute(_ongoingRequest.get()));
152151
if (_ongoingResponse.get().getCode() != 200) {
153152
return false;
154153
}

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<modelVersion>4.0.0</modelVersion>
55
<groupId>io.split.client</groupId>
66
<artifactId>java-client-parent</artifactId>
7-
<version>4.1.2</version>
7+
<version>4.1.3-rc1</version>
88
<dependencyManagement>
99
<dependencies>
1010
<dependency>

testing/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<parent>
77
<groupId>io.split.client</groupId>
88
<artifactId>java-client-parent</artifactId>
9-
<version>4.1.2</version>
9+
<version>4.1.3-rc1</version>
1010
</parent>
1111

1212
<artifactId>java-client-testing</artifactId>

0 commit comments

Comments
 (0)