async-http-client icon indicating copy to clipboard operation
async-http-client copied to clipboard

Make RemotelyClosedException Read Only or Throw New

Open NMcCloud opened this issue 6 years ago • 5 comments

Can the RemotelyClosedException be made read only, or can a new one be thrown every time? The issue is that the exception is basically static, but is maniplulatable, allowing the cause to be altered, suppressed exceptions to be added, and the stack trace modified, which has a fake stack trace to start with. This goes for other similar exceptions like ChannelClosedException. At the very least, user code should be prevented from modifying it.

Just out of curiosity, why is a new exception not thrown?

NMcCloud avatar Jun 15 '19 05:06 NMcCloud

At the very least, user code should be prevented from modifying it.

Contributions welcome.

Just out of curiosity, why is a new exception not thrown?

RemotelyClosedException is used for flow control for retry. We don't want to copy native stacktrace for this. Netty does that a lot too. And we reduce stacktrace because those exceptions are thrown from one single point in the code and we don't want to flood logging once they are thrown.

slandelle avatar Jun 17 '19 20:06 slandelle

Can we make them unmodifiable then, using the special constructor that prevents stack trace modification and suppressed exceptions.

NMcCloud avatar Jun 18 '19 03:06 NMcCloud

Can we make them unmodifiable then, using the special constructor that prevents stack trace modification and suppressed exceptions.

Hardly, this constructor is on Throwable so we can't extend IOException.

I don't think what you'd like to do is feasible without losing the one level stacktrace we currently have in ThrowableUtil#unknownStackTrace.

slandelle avatar Jun 18 '19 08:06 slandelle

FYI, we do the exact same thing as Netty: https://github.com/netty/netty/blob/4.1/common/src/main/java/io/netty/util/internal/ThrowableUtil.java#L30-L33.

slandelle avatar Jun 18 '19 09:06 slandelle

Okay. Will figure out which exceptions these are and prevent their modification another way.

The issue can be closed.

NMcCloudTower avatar Jun 19 '19 22:06 NMcCloudTower