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 #3377

Closed

Conversation

cdfive
Copy link
Collaborator

@cdfive cdfive commented Apr 18, 2024

Describe what this PR does / why we need it

当项目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
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
Copy link
Collaborator

这个修复没问题哈,感谢贡献!方便的话能否帮忙提个PR到目前的默认分支1.8

@LearningGp
Copy link
Collaborator

1.8 已合并,master 我们后续整体同步

@LearningGp LearningGp closed this Apr 29, 2024
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.

2 participants