facebook / wangle

Wangle is a framework providing a set of common client/server abstractions for building services in a consistent, modular, and composable way.
Apache License 2.0
3.04k stars 536 forks source link

Correctly handling readEOF and readException #54

Closed shivramk closed 7 years ago

shivramk commented 7 years ago

What is the right way to deal with readEOF and readException? My understanding is that one needs to close the context on readEOF otherwise the pipeline object will never get destroyed. The echo server example doesn't do this. Isn't this a problem?

Should the context also be closed on readException or is this condition recoverable?

viswanathgs commented 7 years ago

You're right, the EchoServer example doesn't override readEOF or readException - it's supposed to be a trivial example to demonstrate the basic usage. Ideally, you would want to close the pipeline both during readEOF and readException. readEOF is called during normal termination conditions like the remote end closed the socket after sending the message, and readException is invoked during exceptions (you might want to check if the exception is terminal before closing the pipeline or if you could proceed, but most socket exceptions are terminal, so you might as well invoke close() on the context after logging the exception, performing cleanup, etc).

Take a look at the proxy example or telnet example for how close() is called on the context in these cases.