Seata: RpcContext.getContext().getAttachment(RootContext.KEY_XID) is null

Created on 8 Oct 2019  ·  5Comments  ·  Source: seata/seata

  • [ ] I have searched the issues of this repository and believe that this is not a duplicate.

Ⅰ. Issue Description

dubbo远程调用,hessian协议,在TransactionPropagationFilter.invoke方法中getAttachment(RootContext.KEY_XID),这个key是大写的,但是RpcContext#attachments中的key是小写的,导致此处无法获取获取传递过来的全局事务id。

导致attachments中的key为小写是因为:
Http11InputBuffer#parseHeader中对用户添加的head name都置为了小写。
然后org.apache.dubbo.rpc.protocol.hessian.HessianProtocol.HessianHandler#handle直接从request取参数,代码如下:
// 直接从request head里取出传递的参数
Enumeration enumeration = request.getHeaderNames();
while (enumeration.hasMoreElements()) {
String key = enumeration.nextElement();
if (key.startsWith(Constants.DEFAULT_EXCHANGER)) {
RpcContext.getContext().setAttachment(key.substring(Constants.DEFAULT_EXCHANGER.length()),
request.getHeader(key));
}
}
// ...

请问这个怎么能解决?

Ⅱ. Describe what happened

If there is an exception, please attach the exception trace:

Just paste your stack trace here!

Ⅲ. Describe what you expected to happen

Ⅳ. How to reproduce it (as minimally and precisely as possible)

服务提供方用hessian协议暴露服务即可:

Ⅴ. Anything else we need to know?

Ⅵ. Environment:

  • JDK version :1.8
  • OS : win10_64
  • spring boot : 2.1.8.RELEASE
  • apache dubbo : 2.7.0
  • hessian : 4.0.38
  • seata-all : 0.8.1

Most helpful comment

@slievrly nginx default auto filter _ header, back end server may be get the header is null, otherwise nginx need configuration underscores_in_headers on; in http {...}, I suggest the header update to tx-xid

All 5 comments

Hi @Daidalose, we detect non-English characters in the issue. This comment is an auto translation from @fescar-robot to help other users to understand this issue.
We encourage you to describe your issue in English which is more friendly to other users.

RpcContext.getContext().getAttachment(RootContext.KEY_XID) is null

  • [ ] I have searched the issues of this repository and believe that this is not a duplicate.

Ⅰ. Issue Description

Dubbo remote call, hessian protocol, getAttachment (RootContext.KEY_XID) in the TransactionPropagationFilter.invoke method, this key is uppercase, but the key in RpcContext#attachments is lowercase, which makes it impossible to get the global transaction id passed in the get.

The reason for the key in the attachments to be lowercase is that the header name added to the user in Http11InputBuffer#parseHeader is lowercase.

How can this be solved?

Ⅱ. Describe what happened

If there is an exception, please attach the exception trace:

Just paste your stack trace here!

Ⅲ. Describe what you expected to happen

Ⅳ. How to reproduce it (as minimally and precisely as possible)

Ⅴ. Anything else we need to know?

Ⅵ. Environment:

  • JDK version :1.8
  • OS : win10_64
  • spring boot : 2.1.8.RELEASE
  • dubbo : 2.7.0
  • seata-all : 0.8.1

@slievrly nginx default auto filter _ header, back end server may be get the header is null, otherwise nginx need configuration underscores_in_headers on; in http {...}, I suggest the header update to tx-xid

1748

@xingfudeshi thanks for you response, but I didn't use nginx in my demo.

@Daidalose I understand that.It may cause by the similar problem.So i refer that issue here.

Was this page helpful?
0 / 5 - 0 ratings