Skip to content

Ensure alert is send when SSLException happens during calling SslHand…#6047

Closed
normanmaurer wants to merge 1 commit into
4.1from
send_alert_when_error_while_unwrap
Closed

Ensure alert is send when SSLException happens during calling SslHand…#6047
normanmaurer wants to merge 1 commit into
4.1from
send_alert_when_error_while_unwrap

Conversation

@normanmaurer
Copy link
Copy Markdown
Member

…ler.unwrap(...)

Motivation:

When the SslHandler.unwrap(...) (which is called via decode(...)) method did produce an SSLException it was possible that the produced alert was not send to the remote peer. This could lead to staling connections if the remote peer did wait for such an alert and the connection was not closed.

Modifications:

  • Ensure we try to flush any pending data when a SSLException is thrown during unwrapping.
  • Fix SniHandlerTest to correct test this
  • Add explicit new test in SslHandlerTest to verify behaviour with all SslProviders.

Result:

The alert is correctly send to the remote peer in all cases.

@normanmaurer normanmaurer self-assigned this Nov 19, 2016
@normanmaurer normanmaurer added this to the 4.0.43.Final milestone Nov 19, 2016
@normanmaurer
Copy link
Copy Markdown
Member Author

@Scottmitch @trustin PTAL

@normanmaurer normanmaurer force-pushed the send_alert_when_error_while_unwrap branch from 97c9dac to 0fb8111 Compare November 19, 2016 07:46
wrap(ctx, false);
} catch (Throwable cause) {
// Fail pending writes.
pendingUnencryptedWrites.removeAndFailAll(cause);
Copy link
Copy Markdown
Member

@Scottmitch Scottmitch Nov 19, 2016

Choose a reason for hiding this comment

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

can you clarify why we no longer want to fail/release all pending writes in the event of an Throwable (other than SSLException)? Are we sure there will be no unchecked exceptions, and if there is will we potentially leak, or hold onto memory until some other event occurs (user forces a close, etc..)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Yes there should only be SSLException.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'm a bit more pessimistic I guess ... we are calling the JDK's SSL APIs which can be backed by a boat load of complexity ... can you make me more comfortable and explain why none of these APIs will throw an unchecked exception under any condition, or if they do that we will handle it gracefully in some other way.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I am just not think catching throwable all the time is hacky and inconsistent. If we really do we should at least do it in a consistent way. So you would prefer this?

Copy link
Copy Markdown
Contributor

@johnou johnou Nov 19, 2016

Choose a reason for hiding this comment

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

@jasontedor had some valid points about not catching throwable everywhere as well, I don't think there is any graceful way of catching OOM and leaving the JVM in good shape.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

@johnou just like it was before PlatformDependent.throwException(cause);.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

totally missed that, was burried under all the comments,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@normanmaurer - yes I would prefer we cleanup here bcz we own the resources.

Copy link
Copy Markdown
Member Author

@normanmaurer normanmaurer Nov 21, 2016

Choose a reason for hiding this comment

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

It's done in the following as part of setHandshakeFailure

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

looking at your commit now 🍺

@normanmaurer
Copy link
Copy Markdown
Member Author

@johnou @Scottmitch PTAL at the followup commit 3396ada . Good to go now ?

Copy link
Copy Markdown
Contributor

@johnou johnou left a comment

Choose a reason for hiding this comment

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

lgtm, could this somewhat be related to #5931?

@normanmaurer
Copy link
Copy Markdown
Member Author

Nope

Am 21.11.2016 um 11:23 schrieb Johno Crawford notifications@github.com:

@johnou approved this pull request.

lgtm, could this somewhat be related to #5931?


You are receiving this because you were assigned.
Reply to this email directly, view it on GitHub, or mute the thread.

ctx.flush();
} catch (Exception e) {
notifyHandshakeFailure(e);
} catch (SSLException e) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

either change this to Throwable or add another catch clause and re-throw to ensure we free our resources?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

@Scottmitch ok can do...

@normanmaurer
Copy link
Copy Markdown
Member Author

PTAL again @Scottmitch

@Scottmitch
Copy link
Copy Markdown
Member

thanks @normanmaurer ship it!

…ler.unwrap(...)

Motivation:

When the SslHandler.unwrap(...) (which is called via decode(...)) method did produce an SSLException it was possible that the produced alert was not send to the remote peer. This could lead to staling connections if the remote peer did wait for such an alert and the connection was not closed.

Modifications:

- Ensure we try to flush any pending data when a SSLException is thrown during unwrapping.
- Fix SniHandlerTest to correct test this
- Add explicit new test in SslHandlerTest to verify behaviour with all SslProviders.

Result:

The alert is correctly send to the remote peer in all cases.
@normanmaurer normanmaurer force-pushed the send_alert_when_error_while_unwrap branch from 602ac48 to a94c1f5 Compare November 21, 2016 19:26
@normanmaurer
Copy link
Copy Markdown
Member Author

normanmaurer commented Nov 21, 2016

Cherry-picked into 4.1 (f289ebf) and 4.0 (fffc1ba)

@normanmaurer normanmaurer deleted the send_alert_when_error_while_unwrap branch November 21, 2016 19:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants