Skip to content

Sleuth Corrupts Spring Integration Error Message Channel Headers #761

Closed
@garyrussell

Description

@garyrussell

See https://stackoverflow.com/questions/46971098/spring-integration-error-channel-handling-broken-when-used-with-spring-cloud-sle

Error channel handling from a messaging gateway.

  1. The MessagingTemplate sets up reply/error channel headers and invokes the flow.
  2. The flow throws an exception.
  3. The template catches the exception and, if there's an error channel, constructs an ErrorMessage with failedMessage payload; new reply/error channels are set up for the error flow.
  4. The error flow returns a result and it is returned to the user.

The sleuth interceptor breaks this logic because it restores the "spent" reply/error channel and, when the error flow returns a reply, we get...

Reply message received but the receiving thread has exited due to an exception while sending the request message:GenericMessage [payload=OOPS...

It's not clear why sleuth is messing with framework headers; shouldn't it just add the span stuff?

Before interceptor on the error channel...

ErrorMessage [payload=org.springframework.integration.transformer.MessageTransformationException: Failed to transform Message; nested exception is org.springframework.messaging.MessageHandlingException: Expression evaluation failed: 1/0; nested exception is java.lang.ArithmeticException: / by zero, failedMessage=GenericMessage [payload=hi, headers={spanTraceId=a5bccb97d0471781, spanId=4562ba4f926027e2, replyChannel=org.springframework.messaging.core.GenericMessagingTemplate$TemporaryReplyChannel@1002de2b, errorChannel=org.springframework.messaging.core.GenericMessagingTemplate$TemporaryReplyChannel@1002de2b, messageSent=true, id=e374cde6-7a8d-26f7-1613-133f965e0c9e, spanSampled=0}], failedMessage=GenericMessage [payload=hi, headers={spanTraceId=a5bccb97d0471781, spanId=4562ba4f926027e2, replyChannel=org.springframework.messaging.core.GenericMessagingTemplate$TemporaryReplyChannel@1002de2b, errorChannel=org.springframework.messaging.core.GenericMessagingTemplate$TemporaryReplyChannel@1002de2b, messageSent=true, id=e374cde6-7a8d-26f7-1613-133f965e0c9e, spanSampled=0}], headers={replyChannel=org.springframework.messaging.core.GenericMessagingTemplate$TemporaryReplyChannel@1ec5225b, errorChannel=org.springframework.messaging.core.GenericMessagingTemplate$TemporaryReplyChannel@1ec5225b, id=3d0bdb1c-3faa-e02d-604b-6c0a29d12987, timestamp=1509119092545}]

After interceptor on the error channel...

GenericMessage [payload=org.springframework.integration.transformer.MessageTransformationException: Failed to transform Message; nested exception is org.springframework.messaging.MessageHandlingException: Expression evaluation failed: 1/0; nested exception is java.lang.ArithmeticException: / by zero, failedMessage=GenericMessage [payload=hi, headers={spanTraceId=a5bccb97d0471781, spanId=4562ba4f926027e2, replyChannel=org.springframework.messaging.core.GenericMessagingTemplate$TemporaryReplyChannel@1002de2b, errorChannel=org.springframework.messaging.core.GenericMessagingTemplate$TemporaryReplyChannel@1002de2b, messageSent=true, id=e374cde6-7a8d-26f7-1613-133f965e0c9e, spanSampled=0}], failedMessage=GenericMessage [payload=hi, headers={spanTraceId=a5bccb97d0471781, spanId=4562ba4f926027e2, replyChannel=org.springframework.messaging.core.GenericMessagingTemplate$TemporaryReplyChannel@1002de2b, errorChannel=org.springframework.messaging.core.GenericMessagingTemplate$TemporaryReplyChannel@1002de2b, messageSent=true, id=e374cde6-7a8d-26f7-1613-133f965e0c9e, spanSampled=0}], headers={spanTraceId=a5bccb97d0471781, spanId=4562ba4f926027e2, replyChannel=org.springframework.messaging.core.GenericMessagingTemplate$TemporaryReplyChannel@1002de2b, errorChannel=org.springframework.messaging.core.GenericMessagingTemplate$TemporaryReplyChannel@1002de2b, messageSent=true, id=df7caa61-a3f7-a1f3-9eb5-52dac85de8fa, spanSampled=0}]

i.e. the error message channel headers are replaced with channels from the failed message; these channels are no longer valid and the result is the gateway receives no reply (or hangs forever if no timeout is specified).

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions