dotCMS / dotCMS/core

fix: Task250604UpdateFolderInodes not in getTaskClassesNoTransaction() causes startup connection leak warnings

Open Beginner friendly
#35,047 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

OKR : Customer Support stale Team : Enablement Type : Defect
Dominant language
Java
Stars
970
Forks
486
Avg merge
3d 33m
Merged PRs (30d)
170

Description

Problem Statement

Task250604UpdateFolderInodes is not registered in TaskLocatorUtil.getTaskClassesNoTransaction(), but it manages its own raw database connections internally via FolderAPIImpl.fixFolderIds(). This creates an unnecessary outer Hibernate transaction that holds a connection open for the full duration of a potentially long-running bulk operation.

Two connections are held while fixFolderIds() runs:

  1. Outer Hibernate connection (conn A): Opened by HibernateUtil.startTransaction() in StartupTasksExecutor. Idle throughout fixFolderIds() since the task manages its own connection directly.

  2. Inner raw connection (conn B): fixFolderIds() opens a second connection directly via DbConnectionFactory.getDataSource().getConnection(), bypassing the thread-local. This is the connection doing the actual bulk work.

Both connections are properly closed/committed after the task completes. However, on large production databases fixFolderIds() can take longer than the 5-minute leakDetectionThreshold configured in SystemEnvDataSourceStrategy (and setenv.sh), causing ProxyLeakTask to fire for both.

Note: @CloseDBIfOpened on fixFolderIds() is not a problem here. CloseDBIfOpenedInterceptor checks connectionExists() on entry — since conn A already exists, isNewConnection = false and the annotation correctly skips the close on exit.

Why warnings are appearing now: fixFolderIds() has accumulated significant additional work over several commits in Aug–Sep 2025:

Commit Change
Aug 2025 Initial implementation
Aug 14 2025 (#32978) Added FixTask00090RecreateMissingFoldersInParentPath pre-step
Aug 28 2025 (#33107) Added template theme fix pre-step
Sep 19 2025 (#33313) Changed constraint handling from ALTER to DROP CONSTRAINT / ADD CONSTRAINT — requires full index rebuild on the folder table

The DROP CONSTRAINT / ADD CONSTRAINT change in particular requires a full table scan and foreign key index rebuild. On large production databases this pushes total execution time beyond 5 minutes. The 5-minute threshold in SystemEnvDataSourceStrategy and setenv.sh is not a recent change — the warnings are appearing now because this task is running for the first time on large production instances where the execution time exceeds the threshold.

Additional bug: Task250604UpdateFolderInodes.class is registered twice in the run-once task list in TaskLocatorUtil (consecutive lines). The duplicate is harmless (the second occurrence is skipped by the version check) but should be removed.

Steps to Reproduce

Start dotCMS on a large production database where Task250604UpdateFolderInodes.forceRun() returns true. On a database with a large folder tree, the following warnings appear after ~5 minutes:

WARN  pool.ProxyLeakTask - Connection leak detection triggered for org.postgresql.jdbc.PgConnection@4ab87b65 on thread main
java.lang.Exception: Apparent connection leak detected
    at com.zaxxer.hikari.HikariDataSource.getConnection(HikariDataSource.java:100)
    at com.dotmarketing.db.DbConnectionFactory.getConnection(DbConnectionFactory.java:253)
    at com.dotmarketing.db.HibernateUtil.getSession(HibernateUtil.java:840)
    at com.dotmarketing.db.HibernateUtil.startTransaction(HibernateUtil.java:1222)
    at com.dotmarketing.startup.StartupTasksExecutor.executeSchemaUpgrades(StartupTasksExecutor.java:258)

WARN  pool.ProxyLeakTask - Connection leak detection triggered for org.postgresql.jdbc.PgConnection@261debf4 on thread main
java.lang.Exception: Apparent connection leak detected
    at com.zaxxer.hikari.HikariDataSource.getConnection(HikariDataSource.java:100)
    at com.dotmarketing.portlets.folders.business.FolderAPIImpl.fixFolderIds(FolderAPIImpl.java:1360)
    at com.dotmarketing.startup.runonce.Task250604UpdateFolderInodes.executeUpgrade(Task250604UpdateFolderInodes.java:38)
    at com.dotmarketing.startup.StartupTasksExecutor.executeSchemaUpgrades(StartupTasksExecutor.java:261)

Acceptance Criteria

  • Task250604UpdateFolderInodes.class is added to getTaskClassesNoTransaction() in TaskLocatorUtil — eliminates the unnecessary outer Hibernate transaction (conn A)
  • The duplicate registration of Task250604UpdateFolderInodes.class in the run-once task list is removed
  • No ProxyLeakTask warnings appear during startup when this upgrade task runs

dotCMS Version

Latest main branch. Warnings appear on large production databases where fixFolderIds() execution time exceeds the 5-minute leakDetectionThreshold.

Severity

Medium - Some functionality impacted

The warnings are false positives — both connections are properly closed after the task completes. However the unnecessary outer Hibernate transaction holding an idle connection throughout the operation should be corrected.

Links

  • Constraint handling change that significantly increased execution time: #33313
  • Affected file: dotCMS/src/main/java/com/dotmarketing/util/TaskLocatorUtil.java
  • Prior art: Task04205MigrateVanityURLToContent was fixed with the same pattern (commit 9655a9cf0a0)

Workaround (no-code): Set DB_LEAK_DETECTION_THRESHOLD=0 to disable leak detection and suppress warnings. This does not fix the underlying structural issue.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in dotCMS/src/main/java/com/dotmarketing/util/TaskLocatorUtil.java and compare the registration of Task250604UpdateFolderInodes with getTaskClassesNoTransaction() and the run-once task list. Use Task04205MigrateVanityURLToContent and commit 9655a9cf0a0 as prior art. Done means the task is registered only where appropriate and startup no longer holds the unnecessary outer connection or emits leak warnings.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, postgresql
Domain
backend, databases
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Quiet
Clarity
Clearly specified
Newbie friendliness
72/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.