Comments (3)
Hi Jonas,
it looks like io.reactivex.netty.channel.AbstractConnectionToChannelBridge
expects the client to terminate the connection. I've not dug super deep into it but the code where the exception is prepared is commented with:
/If the subscriber is still active, then it expects data but the channel is closed./
Here is an example that shows how to escape (and test) the exception. I've also added some fixes for bugs that are in your original code.
import io.netty.buffer.ByteBuf;
import io.reactivex.netty.channel.Connection;
import io.reactivex.netty.protocol.tcp.client.TcpClient;
import io.reactivex.netty.protocol.tcp.server.TcpServer;
import org.testng.annotations.Test;
import rx.Observable;
import rx.observables.StringObservable;
import rx.observers.TestSubscriber;
import java.nio.channels.ClosedChannelException;
import java.nio.charset.Charset;
import java.util.stream.Stream;
public class TcpTest {
@Test
public void testSinkClosedChannelException() throws Exception {
int count = 100;
TcpServer<ByteBuf, ByteBuf> server = TcpServer.newServer(0)
.start(
c ->
c.writeString(
Observable.range(0, count)
.map(i -> i + ",")
)
);
TestSubscriber<Integer> testSubscriber = new TestSubscriber<>();
TcpClient.newClient("127.0.0.1", server.getServerPort())
.createConnectionRequest()
.flatMap(Connection::getInput)
.map(
b -> {
// must free the ByteBuf
String s = b.toString(Charset.defaultCharset());
b.release();
return s;
}
)
// can't guarantee that the block boundaries will line up so we force split
.compose(o -> StringObservable.split(o, ","))
.map(Integer::parseInt)
.onErrorResumeNext(
e -> {
if (e instanceof ClosedChannelException) {
// sink ClosedChannelException to nothing
return Observable.empty();
}
// 'rethrow' all other errors
return Observable.error(e);
}
)
.subscribe(testSubscriber);
testSubscriber.awaitTerminalEvent();
testSubscriber.assertValueCount(count);
testSubscriber.assertValues(
Stream.iterate(0, i -> i + 1).limit(count).toArray(Integer[]::new)
);
testSubscriber.assertNoErrors();
}
from rxnetty.
Thank you for a quick reply!
Catching the ClosedChannelException and returning empty will work, but I was more interested in the thoughts behind considering a connection closed by the server as an error. I tried to dig down in the commits for some clues, but there is just one large commit by @NiteshKant ( 9da1977#diff-cb86b4ce0a39c9fea0a3174ae12680feR99 ) where this was changed from onCompleted to onError.
I will try to understand why this does not happen when using HttpServer + HttpClient.
from rxnetty.
Yeah, beyond that comment I have no idea. Nothing struck me in the commit either. I had wondered if it is to signal client close vs server close (which would otherwise be lost) because Netflix had a socket client that needed to know this, but that's pure speculation.
from rxnetty.
Related Issues (20)
- Adding PipelineConfigurator in RxNetty 0.5.x HOT 1
- My async client keeps getting “Content stream is already disposed” error HOT 2
- Any plan to build RxNetty on top of RxJava 2?
- ConnectionHandler on 0.5.x-java2 branch imports rx.Observable HOT 1
- For large POSTs RxNetty seems to need to write everything before reading anything HOT 6
- 0.5 Intuitive bytebuf handling HOT 2
- RxNetty 0.5.2 stable? HOT 4
- Create Http Client without binding it to an endpoint HOT 3
- [0.4.20] NullPointException when closing socket HOT 2
- Writes out of order when using multiple threads
- Does RxNetty support http2 multiplexing? HOT 1
- why before response.close() must response.getChannel().deregister()? HOT 2
- Unnecessary synchronised lock
- Connection Leak 0.5.2 HOT 6
- require for documentation around how backpressure works HOT 4
- HTTP POST example (REST) HOT 4
- [SECURITY] unsafeSecure() should not be used in samples HOT 1
- ResourceLeakDetector,LEAK: ByteBuf.release()
- HTTPS Server with RxNetty and existing certificate
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from rxnetty.