RxNetty icon indicating copy to clipboard operation
RxNetty copied to clipboard

why before response.close() must response.getChannel().deregister()?

Open ahu0605 opened this issue 7 years ago • 2 comments

if I do not excute response.getChannel().deregister() ,the server will throws IOExcption : An existing connection was forcibly closed by the remote host ? why???? the http client code has some mistake ?

ahu0605 avatar Jun 16 '18 19:06 ahu0605

Are you fronting this with a proxy? We have a similar problem where HAProxy force closes the connection with RST and Netty returns a IOException when it tries to FIN the already closed connection. Ours reports as either this or Connection reset by peer. If it's something similar to this, it is because Netty is unopinionated about handling rude connection closes and forces the errors down into the handlers. My guess is they don't want to accidentally clobber any important unexpected behaviour.

Your best bet is to add

.catch(
  e -> {
    if (
      e instanceOf IOException && 
      "An existing connection was forcibly closed by the remote host.".equals(e.getMessage())
    ) {
      return Observable.empty();
    } else {
      return Observable.throw(e);
    }
  }
)

to your observable.

cf, https://stackoverflow.com/questions/21550337/haproxy-netty-way-to-prevent-exceptions-on-connection-reset

jamesgorman2 avatar Jun 17 '18 02:06 jamesgorman2

oh,I just run the demo the client is http client get a request ,then the server happen exception

ahu0605 avatar Jun 17 '18 03:06 ahu0605