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

Fix when duplication spi class found using SpiLoader #3387

Merged
merged 1 commit into from
Apr 28, 2024

Conversation

cdfive
Copy link
Collaborator

@cdfive cdfive commented Apr 28, 2024

Describe what this PR does / why we need it

#3377 相同,补充申请PR提交到1.8分支

当项目jar依赖包里有重复sentinel包,目前SpiLoader加载META-INF/services里的SPI扩展类,如果发现有重复的已解析过的扩展类,会抛出异常提示,导致相关功能无法运行。

这种场景可能更好的处理方式是程序不抛异常,在日志中记录该情况便于排查,已解析过的扩展类跳过处理,让程序正常运行。

Does this pull request fix one issue?

Fixes #3376

Describe how you did it

SpiLoader里的classMap存储了已解析的扩展类,其中value类型为Class,可通过value来检查重复。

Describe how to verify it

1.在spring-webmvc的demo里,添加META-INF/services目录,拷贝sentinel-core里的部分配置,启动WebMvcDemoApplication类,访问接口测试并检查日志情况。

2.在项目里引用2个不同版本的sentinel-core,启动项目进行限流相关测试。

Special notes for reviews

优化了该类的一些日志打印,打印出SPI扩展文件地址,用于日志排查。

Copy link

codecov bot commented Apr 28, 2024

Codecov Report

Attention: Patch coverage is 11.11111% with 8 lines in your changes are missing coverage. Please review.

Project coverage is 45.93%. Comparing base (cd02b1d) to head (0b40b37).

Files Patch % Lines
...n/java/com/alibaba/csp/sentinel/spi/SpiLoader.java 11.11% 7 Missing and 1 partial ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##                1.8    #3387      +/-   ##
============================================
+ Coverage     45.89%   45.93%   +0.03%     
- Complexity     2145     2147       +2     
============================================
  Files           431      431              
  Lines         12903    12906       +3     
  Branches       1727     1728       +1     
============================================
+ Hits           5922     5928       +6     
+ Misses         6279     6277       -2     
+ Partials        702      701       -1     
Components Coverage Δ
sentinel-adapter 43.22% <ø> (ø)
sentinel-cluster 23.78% <ø> (+0.07%) ⬆️
sentinel-core 59.58% <11.11%> (-0.04%) ⬇️
sentinel-extension 46.36% <ø> (+0.17%) ⬆️
sentinel-logging 54.54% <ø> (ø)

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

Copy link
Collaborator

@LearningGp LearningGp left a comment

Choose a reason for hiding this comment

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

LGTM

@LearningGp LearningGp merged commit dbd3c06 into alibaba:1.8 Apr 28, 2024
9 of 10 checks passed
@LearningGp
Copy link
Collaborator

Thanks for contributing!

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

Successfully merging this pull request may close these issues.

Spi重复初始化资源问题
2 participants