Skip to content

Commit 8a07213

Browse files
committed
Merge pull request #17 from ReactiveSocket/stevegury/propagate-cancellation
Propagate cancellation when a TransportException occurs
2 parents de0cb9d + 1795636 commit 8a07213

3 files changed

Lines changed: 17 additions & 4 deletions

File tree

reactivesocket-aeron/src/main/java/io/reactivesocket/aeron/client/AeronClientDuplexConnection.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,22 +79,22 @@ public void dispose() {
7979
public void addOutput(Publisher<Frame> o, Completable callback) {
8080
o
8181
.subscribe(new Subscriber<Frame>() {
82-
private Subscription s;
82+
private Subscription subscription;
8383

8484
@Override
8585
public void onSubscribe(Subscription s) {
86-
this.s = s;
86+
this.subscription = s;
8787
s.request(128);
8888

8989
}
9090

9191
@Override
9292
public void onNext(Frame frame) {
9393
if (isTraceEnabled()) {
94-
trace("onNext subscription => {} and frame => {}", s.toString(), frame.toString());
94+
trace("onNext subscription => {} and frame => {}", subscription.toString(), frame.toString());
9595
}
9696

97-
final FrameHolder fh = FrameHolder.get(frame, publication, s);
97+
final FrameHolder fh = FrameHolder.get(frame, publication, subscription);
9898
boolean offer;
9999
do {
100100
offer = frameSendQueue.offer(fh);
@@ -105,6 +105,7 @@ public void onNext(Frame frame) {
105105
public void onError(Throwable t) {
106106
if (t instanceof NotConnectedException) {
107107
callback.error(new TransportException(t));
108+
subscription.cancel();
108109
} else {
109110
callback.error(t);
110111
}

reactivesocket-netty/src/main/java/io/reactivesocket/netty/tcp/client/ClientTcpDuplexConnection.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,11 @@ public final Observable<Frame> getInput() {
9898
@Override
9999
public void addOutput(Publisher<Frame> o, Completable callback) {
100100
o.subscribe(new Subscriber<Frame>() {
101+
private Subscription subscription;
102+
101103
@Override
102104
public void onSubscribe(Subscription s) {
105+
subscription = s;
103106
s.request(Long.MAX_VALUE);
104107
}
105108

@@ -126,6 +129,9 @@ public void onNext(Frame frame) {
126129
@Override
127130
public void onError(Throwable t) {
128131
callback.error(t);
132+
if (t instanceof TransportException) {
133+
subscription.cancel();
134+
}
129135
}
130136

131137
@Override

reactivesocket-netty/src/main/java/io/reactivesocket/netty/websocket/client/ClientWebSocketDuplexConnection.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,11 @@ public final Observable<Frame> getInput() {
119119
@Override
120120
public void addOutput(Publisher<Frame> o, Completable callback) {
121121
o.subscribe(new Subscriber<Frame>() {
122+
private Subscription subscription;
123+
122124
@Override
123125
public void onSubscribe(Subscription s) {
126+
subscription = s;
124127
s.request(Long.MAX_VALUE);
125128
}
126129

@@ -148,6 +151,9 @@ public void onNext(Frame frame) {
148151
@Override
149152
public void onError(Throwable t) {
150153
callback.error(t);
154+
if (t instanceof TransportException) {
155+
subscription.cancel();
156+
}
151157
}
152158

153159
@Override

0 commit comments

Comments
 (0)