Skip to content

Add withReadTimeout(Integer) method to NettyDockerCmdExecFactory #982

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 12, 2018
Merged

Add withReadTimeout(Integer) method to NettyDockerCmdExecFactory #982

merged 1 commit into from
Mar 12, 2018

Conversation

pjdarton
Copy link
Contributor

@pjdarton pjdarton commented Jan 22, 2018

This enhances our Netty support so that, like
JerseyDockerCmdExecFactory, we have a withReadTimeout(milliseconds)
method that configures the factory to implement a read timeout.
This allows clients to cope with recalcitrant docker daemons - if the
daemon stops responding then the client code will get a
SocketTimeoutException (much like it would if it was using Jersey
instead of Netty) instead of just hanging forever.
See issue #588


This change is Reviewable

This enhances our Netty support so that, like
JerseyDockerCmdExecFactory, we have a withReadTimeout(milliseconds)
method that configures the factory to implement a read timeout.
This allows clients to cope with recalcitrant docker daemons - if the
daemon stops responding then the client code will get a
SocketTimeoutException (much like it would if it was using Jersey
instead of Netty) instead of just hanging forever.
*/
@Override
protected synchronized void channelIdle(ChannelHandlerContext ctx, IdleStateEvent evt) throws Exception {
assert evt.state() == IdleState.READER_IDLE;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

did you copy it from somewhere?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not "copied". It was coded by initially using the ReadTimeoutHandler class as specified by its Javadoc, but then developed from there.

Using it as-documented was a long way from ideal because Netty's ReadTimeoutHandler throws a peculiar exception (with no stacktrace) when it triggers, with no proper error message, which is why its javadoc suggests that you then add a second handler class to turn the thrown exception into the exception you really wanted. Ideally it'd be possible to extend/configure their class with your own functionality to control the exception (or for their class to throw a decent exception to start with!), but they don't provide for that.
So what I ended up doing instead was to throw the exception that I really wanted from the outset, using Netty's more generic IdleStateHandler as the parent class (as Netty's ReadTimeoutHandler does) and going from there.

It's not the most original bit of coding ever because of the constraints (it needs to fit within Netty's APIs), but it's not a copy - there's a finite amount of difference that's possible while still having code that works.

@KostyaSha KostyaSha added this to the 3.1.0-rc-2 milestone Feb 20, 2018
@KostyaSha KostyaSha merged commit 528cc69 into docker-java:master Mar 12, 2018
@pjdarton pjdarton deleted the add_netty_read_timeout branch June 19, 2020 10:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants