Skip to content

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

Closed

Description

@wuchubuzai2018

当前可能存在的问题

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

我思考的解决办法

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

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

Activity

  1. KomachiSion commented on Jun 23, 2022

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

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

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

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

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

  3. KomachiSion commented on Jun 24, 2022

    @KomachiSion
    Collaborator

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

                //close old datasource.
                if (dataSourceListOld != null && !dataSourceListOld.isEmpty()) {
                    for (HikariDataSource dataSource : dataSourceListOld) {
                        dataSource.close();
                    }
                }
    
  4. wuchubuzai2018 commented on Jun 25, 2022

    @wuchubuzai2018
    ContributorAuthor

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

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

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

  5. KomachiSion commented on Jun 27, 2022

    @KomachiSion
    Collaborator

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

  6. added
    kind/enhancementCategory issues or prs related to enhancement.
    and removed on Jun 27, 2022
  7. added this to the 2.1.2 milestone on Sep 22, 2022
  8. added a commit that references this issue on Sep 26, 2022
  9. added a commit that references this issue on Sep 26, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions