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

拒绝策略为CallerRunsPolicy时,MdcRunnable会删除主线程mdc信息【bug】 #330

Closed
GavinZ1314 opened this issue Sep 13, 2023 · 11 comments
Labels
bug Something isn't working

Comments

@GavinZ1314
Copy link

首先感谢您使用 DynamicTp,如果使用过程中有任何问题,请按照下述模板反馈问题,建议使用 Markdown 语法

版本信息

  • Jdk版本:8
  • SpringBoot版本:2
  • DynamicTp版本:1.1.3
  • 配置中心版本:nacos1.2

问题描述

文字描述、截图、粘代码方式

  • 配置文件:
  • 代码使用步骤:
  • 报错信息:
  • 猜测可能原因:

复现步骤

  1. 当使用MdcTaskWrapper和线程池使用callRuns拒绝策略时执行到主线程会将MDC的数据清除, 应该在new Wrapper时传递当前线程(主线程), finally时判断不为主线程再清除MDC信息

其他信息

  1. xxx
  2. xxx
@GavinZ1314 GavinZ1314 added the bug Something isn't working label Sep 13, 2023
@yanhom1314 yanhom1314 changed the title bug 拒绝策略为CallerRunsPolicy时,MdcRunnable会删除主线程mdc信息【bug】 Sep 14, 2023
@yanhom1314
Copy link
Collaborator

感谢反馈,是个问题,有兴趣可以提个pr修复下

@GavinZ1314
Copy link
Author

可以的, 不过我也很奇怪traceId没丢, 这块是为啥? 不过我想应该不用把mdc的其他属性和traceId分开处理吧, 这块能讲下设计思路么

@yanhom1314
Copy link
Collaborator

可以的, 不过我也很奇怪traceId没丢, 这块是为啥? 不过我想应该不用把mdc的其他属性和traceId分开处理吧, 这块能讲下设计思路么

traceId没丢是因为在mdcRunnable#run执行后没有remove traceId信息。之所以这样设计是因为afterExecute方法里做执行超时告警时需要traceId,其他mdc相关信息用不到,所以其他mdc信息在退出mdcRunnable#run方法时需要清理掉,traceId信息需要在afterExecute执行后在单独清理。

@GavinZ1314
Copy link
Author

好的, 想到了, afterExecute如果走到拒绝策略就不调这方法了, 那基于这点是否需要把afterExecute的处理逻辑要提到run里呢

@yanhom1314
Copy link
Collaborator

好的, 想到了, afterExecute如果走到拒绝策略就不调这方法了, 那基于这点是否需要把afterExecute的处理逻辑要提到run里呢

走了拒绝策略的就先不考虑这些了,afterExecute的处理又依赖beforeExecute的逻辑,比较复杂。先就处理走了拒绝策略不要清除掉主线程的mdc信息就行。

@GavinZ1314
Copy link
Author

好的

@KamToHung
Copy link
Collaborator

@yanhom1314 MdcRunnable中我们只要清理parentMdc即可?因为parentMdc是我们构造函数设置的,所以我们清理也是应当;但MDC中的数据有可能是主线程设置的,那这个时候clean是否是主线程行为决定

@yanhom1314
Copy link
Collaborator

@yanhom1314 MdcRunnable中我们只要清理parentMdc即可?因为parentMdc是我们构造函数设置的,所以我们清理也是应当;但MDC中的数据有可能是主线程设置的,那这个时候clean是否是主线程行为决定

现在是只会清理parentMdc中的kv,其他mdc字段不清理的,没问题的。

@KamToHung
Copy link
Collaborator

@yanhom1314 MdcRunnable中我们只要清理parentMdc即可?因为parentMdc是我们构造函数设置的,所以我们清理也是应当;但MDC中的数据有可能是主线程设置的,那这个时候clean是否是主线程行为决定

现在是只会清理parentMdc中的kv,其他mdc字段不清理的,没问题的。

好像现在MdcRunnable中通过MDC.remove移除MDC的kv

@GavinZ1314
Copy link
Author

pr的话基于master拉分支么

@KamToHung
Copy link
Collaborator

KamToHung commented Sep 25, 2023

pr的话基于master拉分支么

是的,不过此issue有同学解决并且合并了(gitee那边)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants