|
16 | 16 |
|
17 | 17 | package io.rsocket; |
18 | 18 |
|
19 | | -import static io.rsocket.util.ExceptionUtil.noStacktrace; |
20 | | - |
21 | 19 | import io.netty.buffer.Unpooled; |
22 | 20 | import io.netty.util.collection.IntObjectHashMap; |
23 | 21 | import io.rsocket.exceptions.ConnectionException; |
24 | 22 | import io.rsocket.exceptions.Exceptions; |
25 | 23 | import io.rsocket.internal.LimitableRequestPublisher; |
26 | 24 | import io.rsocket.util.PayloadImpl; |
| 25 | +import org.reactivestreams.Publisher; |
| 26 | +import org.reactivestreams.Subscriber; |
| 27 | +import reactor.core.Disposable; |
| 28 | +import reactor.core.publisher.*; |
| 29 | + |
| 30 | +import javax.annotation.Nullable; |
27 | 31 | import java.nio.channels.ClosedChannelException; |
28 | 32 | import java.time.Duration; |
29 | 33 | import java.util.Collection; |
|
32 | 36 | import java.util.function.Consumer; |
33 | 37 | import java.util.function.Function; |
34 | 38 | import java.util.function.Supplier; |
35 | | -import javax.annotation.Nullable; |
36 | | -import org.reactivestreams.Publisher; |
37 | | -import org.reactivestreams.Subscriber; |
38 | | -import reactor.core.Disposable; |
39 | | -import reactor.core.publisher.*; |
| 39 | + |
| 40 | +import static io.rsocket.util.ExceptionUtil.noStacktrace; |
40 | 41 |
|
41 | 42 | /** Client Side of a RSocket socket. Sends {@link Frame}s to a {@link RSocketServer} */ |
42 | 43 | class RSocketClient implements RSocket { |
@@ -419,29 +420,39 @@ private boolean contains(int streamId) { |
419 | 420 | } |
420 | 421 |
|
421 | 422 | protected void cleanup() { |
422 | | - senders.forEach( |
423 | | - (integer, limitableRequestPublisher) -> |
424 | | - cleanUpLimitableRequestPublisher(limitableRequestPublisher)); |
425 | | - |
426 | | - receivers.forEach((integer, subscriber) -> cleanUpSubscriber(subscriber)); |
427 | | - |
428 | | - synchronized (this) { |
| 423 | + Collection<Subscriber<Payload>> subscribers; |
| 424 | + Collection<LimitableRequestPublisher> publishers; |
| 425 | + synchronized (RSocketClient.this) { |
| 426 | + subscribers = receivers.values(); |
| 427 | + publishers = senders.values(); |
| 428 | + |
429 | 429 | senders.clear(); |
430 | 430 | receivers.clear(); |
431 | 431 | } |
432 | 432 |
|
| 433 | + subscribers.forEach(this::cleanUpSubscriber); |
| 434 | + publishers.forEach(this::cleanUpLimitableRequestPublisher); |
| 435 | + |
433 | 436 | if (null != keepAliveSendSub) { |
434 | 437 | keepAliveSendSub.dispose(); |
435 | 438 | } |
436 | 439 | } |
437 | 440 |
|
438 | 441 | private synchronized void cleanUpLimitableRequestPublisher( |
439 | 442 | LimitableRequestPublisher<?> limitableRequestPublisher) { |
440 | | - limitableRequestPublisher.cancel(); |
| 443 | + try { |
| 444 | + limitableRequestPublisher.cancel(); |
| 445 | + } catch (Throwable t) { |
| 446 | + errorConsumer.accept(t); |
| 447 | + } |
441 | 448 | } |
442 | 449 |
|
443 | 450 | private synchronized void cleanUpSubscriber(Subscriber<?> subscriber) { |
444 | | - subscriber.onError(CLOSED_CHANNEL_EXCEPTION); |
| 451 | + try { |
| 452 | + subscriber.onError(CLOSED_CHANNEL_EXCEPTION); |
| 453 | + } catch (Throwable t) { |
| 454 | + errorConsumer.accept(t); |
| 455 | + } |
445 | 456 | } |
446 | 457 |
|
447 | 458 | private void handleIncomingFrames(Frame frame) { |
|
0 commit comments