-
Notifications
You must be signed in to change notification settings - Fork 465
Trigger fault sequence for forceful connection closures #2431
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
base: master
Are you sure you want to change the base?
Conversation
WalkthroughAdds a public Changes
Sequence Diagram(s)sequenceDiagram
participant Backend
participant TargetHandler
participant Connection
participant Metrics
participant TargetErrorHandler
Backend->>TargetHandler: endOfInput(conn)
TargetHandler->>TargetHandler: read ProtocolState & previous state
Note right of TargetHandler: log diagnostic info
alt state is REQUEST_HEAD or REQUEST_BODY
TargetHandler->>TargetHandler: informWriterError(conn)
else state is RESPONSE_HEAD or RESPONSE_BODY
TargetHandler->>TargetHandler: informReaderError(conn)
end
TargetHandler->>Metrics: disconnected()
TargetHandler->>Connection: set state -> CLOSED
TargetHandler->>Connection: shutdown/close aggressively
alt previous state != RESPONSE_DONE and request msg ctx exists
TargetHandler->>TargetHandler: mark internal origin = ERROR_HANDLER
TargetHandler->>TargetErrorHandler: forward(SND_IO_ERROR, current state)
else
Note right of TargetHandler: no error forwarding
end
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing touches
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
modules/transports/core/nhttp/src/main/java/org/apache/synapse/transport/passthru/TargetHandler.java(1 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
modules/transports/core/nhttp/src/main/java/org/apache/synapse/transport/passthru/TargetHandler.java (2)
modules/transports/core/nhttp/src/main/java/org/apache/synapse/transport/passthru/TargetContext.java (1)
TargetContext(34-258)modules/transports/core/nhttp/src/main/java/org/apache/synapse/transport/passthru/PassThroughConstants.java (1)
PassThroughConstants(19-280)
🔇 Additional comments (1)
modules/transports/core/nhttp/src/main/java/org/apache/synapse/transport/passthru/TargetHandler.java (1)
1069-1086: Add metrics update and correlation logging toendOfInput()to match the error-handling pattern inexception().The review comment is valid. Verification confirms:
endOfInput()callsshutdownConnection(conn, true)which invokesconn.shutdown()rather thanconn.close(), preventing theclosed()callback from being triggered and bypassing themetrics.disconnected()call at line 832.
endOfInput()lacks correlation logging entirely, whereasexception()conditionally logs to correlation log when enabled (lines 1158-1160).Since
endOfInput()represents an error path (unexpected connection termination), it should mirror the telemetry pattern inexception(): addmetrics.disconnected()directly and conditionally log to correlation log usinglogHttpRequestErrorInCorrelationLog()whenPassThroughCorrelationConfigDataHolder.isEnable()is true.
...transports/core/nhttp/src/main/java/org/apache/synapse/transport/passthru/TargetHandler.java
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
modules/transports/core/nhttp/src/main/java/org/apache/synapse/transport/passthru/TargetHandler.java(1 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
modules/transports/core/nhttp/src/main/java/org/apache/synapse/transport/passthru/TargetHandler.java (2)
modules/transports/core/nhttp/src/main/java/org/apache/synapse/transport/passthru/TargetContext.java (1)
TargetContext(34-258)modules/transports/core/nhttp/src/main/java/org/apache/synapse/transport/passthru/PassThroughConstants.java (1)
PassThroughConstants(19-280)
...transports/core/nhttp/src/main/java/org/apache/synapse/transport/passthru/TargetHandler.java
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (1)
modules/transports/core/nhttp/src/main/java/org/apache/synapse/transport/passthru/TargetHandler.java (1)
1069-1098: MoverequestMsgCtxretrieval before connection shutdown.The implementation correctly addresses the PR objectives and previous review comments (pipe notifications, metrics update). However,
requestMsgCtxis retrieved at line 1088 aftershutdownConnection()at line 1087, which is inconsistent with the pattern used inclosed()(line 769),timeout()(line 872), andexception()(line 1102) where the message context is retrieved before any cleanup operations.While this likely works since the context remains attached to the connection's
HttpContext, moving the retrieval earlier ensures consistency and guards against potential fragility if shutdown behavior changes.Proposed fix
public void endOfInput(NHttpClientConnection conn) throws IOException { ProtocolState state = TargetContext.getState(conn); + MessageContext requestMsgCtx = TargetContext.get(conn).getRequestMsgCtx(); log.warn("Connection ended unexpectedly" + ", " + getConnectionLoggingInfo(conn) + ", State: " + state + "."); // Notify pipes based on state to prevent thread hangs if (state == ProtocolState.REQUEST_HEAD || state == ProtocolState.REQUEST_BODY) { informWriterError(conn); } else if (state == ProtocolState.RESPONSE_HEAD || state == ProtocolState.RESPONSE_BODY) { informReaderError(conn); } // Update metrics metrics.disconnected(); TargetContext.updateState(conn, ProtocolState.CLOSED); targetConfiguration.getConnections().shutdownConnection(conn, true); - MessageContext requestMsgCtx = TargetContext.get(conn).getRequestMsgCtx(); if (state != ProtocolState.RESPONSE_DONE && requestMsgCtx != null) { requestMsgCtx.setProperty(PassThroughConstants.INTERNAL_EXCEPTION_ORIGIN, PassThroughConstants.INTERNAL_ORIGIN_ERROR_HANDLER); targetErrorHandler.handleError(requestMsgCtx, ErrorCodes.SND_IO_ERROR, "Error in Sender", null, state); } }
📜 Review details
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
modules/transports/core/nhttp/src/main/java/org/apache/synapse/transport/passthru/TargetHandler.java
Purpose
To fix wso2/api-manager#4414
Approach
Samples
N/A
Summary by CodeRabbit
✏️ Tip: You can customize this high-level summary in your review settings.