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

建议ExternalStoragePersistServiceImpl类实现对数据源的销毁destory操作 #8611

Closed
wuchubuzai2018 opened this issue Jun 22, 2022 · 5 comments · Fixed by #9212
Closed
Assignees
Labels
area/Config good first issue Good for newcomers kind/enhancement Category issues or prs related to enhancement.
Milestone

Comments

@wuchubuzai2018
Copy link
Contributor

wuchubuzai2018 commented Jun 22, 2022

当前可能存在的问题

nacos-config模块中的ExternalStoragePersistServiceImpl类在启动时调用了如下代码创建了数据源,并在内存中维护了数据源对象
dataSourceService = DynamicDataSource.getInstance().getDataSource();
但是,并没有一个地方去销毁这些创建的数据源,在某些容器上重新启动或重新加载当前项目时,可能数据源未执行销毁操作,导致数据库连接处于占用问题。

我思考的解决办法

1、建议在ExternalDataSourceServiceImpl类中提供销毁数据源链接的方法 ,以实现对如下代码的资源关闭。
private List dataSourceList = new ArrayList<>();
2、建议在ExternalStoragePersistServiceImpl实现spring destory生命周期方法,并调用dataSourceService中维护的关闭方法

如果认为这个可以进行优化,我是否可以下载代码并提交一个PR呢

@KomachiSion
Copy link
Collaborator

  1. 关闭数据库连接的原因是什么? 正常来说nacos进程只要还在,就不需要关闭数据库连接。
  2. 程序关闭时会关闭连接,这个是HikariCP自动会做的事。
  3. 重新启动还有连接存在,说明前一个容器上的进程应该没有顺利推出,只是容器不可见了,应该需要查一下这个问题。否则你加了销毁方法也不会调用到。

@wuchubuzai2018
Copy link
Contributor Author

  1. 关闭数据库连接的原因是什么? 正常来说nacos进程只要还在,就不需要关闭数据库连接。

    1. 程序关闭时会关闭连接,这个是HikariCP自动会做的事。

    2. 重新启动还有连接存在,说明前一个容器上的进程应该没有顺利推出,只是容器不可见了,应该需要查一下这个问题。否则你加了销毁方法也不会调用到。

或者我这么说ExternalStoragePersistServiceImpl这个类中提供了reload数据源的方法,虽然暂时没有用到,但是这个方法被多次调用时未销毁以前的数据源,可能为未来留下隐患吧,我想是不是可以在这个方法实现内部去判断,如果之前有数据源就先调用待实现的close数据源方法,在进行加载

@KomachiSion
Copy link
Collaborator

您真的认真阅读代码了吗? reload中会关闭就数据源

            //close old datasource.
            if (dataSourceListOld != null && !dataSourceListOld.isEmpty()) {
                for (HikariDataSource dataSource : dataSourceListOld) {
                    dataSource.close();
                }
            }

@wuchubuzai2018
Copy link
Contributor Author

您真的认真阅读代码了吗? reload中会关闭就数据源

            //close old datasource.
            if (dataSourceListOld != null && !dataSourceListOld.isEmpty()) {
                for (HikariDataSource dataSource : dataSourceListOld) {
                    dataSource.close();
                }
            }

老哥啊,你这个代码在哪个文件的第几行啊,找了一圈也没有看见啊

@KomachiSion
Copy link
Collaborator

哦, 好像是缺少了。 我看的是别的分支。 develop分支没有。

@KomachiSion KomachiSion added kind/enhancement Category issues or prs related to enhancement. and removed status/wontfix This will not be worked on labels Jun 27, 2022
@KomachiSion KomachiSion added good first issue Good for newcomers and removed status/need discuss labels Sep 19, 2022
@KomachiSion KomachiSion added this to the 2.1.2 milestone Sep 22, 2022
KomachiSion added a commit to KomachiSion/nacos that referenced this issue Sep 26, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/Config good first issue Good for newcomers kind/enhancement Category issues or prs related to enhancement.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants