Skip to content
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

Add remote address information in SessionProtocolNegotiationException #6113

Conversation

kth496
Copy link
Contributor

@kth496 kth496 commented Feb 19, 2025

Motivation:

Adding the remoteAddress (i.e., the actual host, IP and port) to the exception message will help users understand which specific endpoint was involved in the failed negotiation.
ref: https://discord.com/channels/1087271586832318494/1087272728177942629/1341444142131183718

I appreciate any kind of feedback!

Modifications:

  • Added SocketAddress remoteAddress in the exception message of SessionProtocolNegotiationException.

Result:

  • Users will see the remoteAddress in the error message when a SessionProtocolNegotiationException occurs.
  • No behavioral changes, but the exception message format is slightly modified.

public SessionProtocolNegotiationException(SessionProtocol expected, @Nullable String reason) {
super(appendReason("expected: " + requireNonNull(expected, "expected"), reason));
public SessionProtocolNegotiationException(SessionProtocol expected,
@Nullable SocketAddress remoteAddress,
Copy link
Contributor

Choose a reason for hiding this comment

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

These are breaking changes. What do you think of adding the remote address to the reason?
If Channel is available when raising SessionProtocolNegotiationException, should we set it as a hint instead? This provides users with more troubleshooting information via Channel.toString().

"...some reason (remoteAddress: ...)"
or 
"...some reason (channel: ...)"

@kth496
Copy link
Contributor Author

kth496 commented Feb 20, 2025

@ikhoon
Thank you for your feedback. I realize I overlooked API compatibility. I have made improvements based on suggestions!

The test modified along with this pull request is failing only on the Windows platform. I don’t have access to a Windows machine, so it’s difficult for me to debug the issue. How would you suggest I approach resolving this?

@kth496 kth496 requested a review from ikhoon February 20, 2025 12:59
Copy link
Contributor

@ikhoon ikhoon left a comment

Choose a reason for hiding this comment

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

Thanks! 🙏🙇‍♂️

@ikhoon ikhoon added this to the 1.32.0 milestone Feb 21, 2025
Copy link
Contributor

@minwoox minwoox left a comment

Choose a reason for hiding this comment

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

Thanks!

desiredProtocol, "previously failed negotiation")),
desiredProtocol,
"previously failed negotiation (remoteAddress: " +
remoteAddress + ")")),
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
remoteAddress + ")")),
remoteAddress + ')')),

@@ -461,7 +461,8 @@ void finishWithNegotiationFailure(
final ChannelPipeline pipeline = ctx.pipeline();
pipeline.channel().eventLoop().execute(
() -> pipeline.fireUserEventTriggered(
new SessionProtocolNegotiationException(expected, actual, reason)));
new SessionProtocolNegotiationException(
expected, actual, reason + " (channel: " + pipeline.channel() + ")")));
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
expected, actual, reason + " (channel: " + pipeline.channel() + ")")));
expected, actual, reason + " (channel: " + pipeline.channel() + ')')));

@@ -174,7 +174,7 @@ private void scheduleSessionTimeout(Channel channel, Promise<Channel> sessionPro
sessionTimeoutFuture = channel.eventLoop().schedule(() -> {
if (sessionPromise.tryFailure(new SessionProtocolNegotiationException(
desiredProtocol,
"connection established, but session creation timed out: " + channel))) {
"connection established, but session creation timed out. (channel: " + channel + ")"))) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
"connection established, but session creation timed out. (channel: " + channel + ")"))) {
"connection established, but session creation timed out. (channel: " + channel + ')'))) {

@minwoox
Copy link
Contributor

minwoox commented Feb 24, 2025

@kth496 Would you mind fixing the test failure in Window CI?

H2WithoutAlpnTest > shouldRejectH2WithoutAlpn() FAILED
    org.opentest4j.AssertionFailedError: 
    Expecting throwable message:
      "com.linecorp.armeria.client.SessionProtocolNegotiationException: expected: h2, actual: h1, reason: unexpected protocol negotiation result (channel: [id: 0x85e4bff0, L:/127.0.0.1:50963 ! R:/127.0.0.1:50962])"
    to contain:
      ["expected: h2",
        "actual: h1",
        "reason: unexpected protocol negotiation result",
        "R:127.0.0.1"]
    but could not find:
      ["R:127.0.0.1"]

    Throwable that failed the check:

Copy link

codecov bot commented Feb 24, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 74.37%. Comparing base (d30a11c) to head (87e93ab).
Report is 7 commits behind head on main.

Additional details and impacted files
@@             Coverage Diff             @@
##             main    #6113       +/-   ##
===========================================
+ Coverage        0   74.37%   +74.37%     
- Complexity      0    22172    +22172     
===========================================
  Files           0     1959     +1959     
  Lines           0    82262    +82262     
  Branches        0    10740    +10740     
===========================================
+ Hits            0    61186    +61186     
- Misses          0    15954    +15954     
- Partials        0     5122     +5122     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@minwoox minwoox merged commit 32e7c3e into line:main Feb 25, 2025
14 checks passed
@minwoox
Copy link
Contributor

minwoox commented Feb 25, 2025

Thanks, @kth496! 👍 👍 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants