komga icon indicating copy to clipboard operation
komga copied to clipboard

Uncancellable task(s) blocking every other tasks of the same kind until restart

Open hugoboissiere opened this issue 6 months ago • 3 comments

Steps to reproduce

Sometimes, when doing a library scan, one or multiple of the task gets stuck and blocks every other task. Clicking the "cancel all tasks" button cancels every tasks except the blocking ones, clicking the button multiple times says there are no tasks to cancel. A restart of the application is required to cancel those tasks.

I had the issue happen multiple times, the most recent ones "AggregateSeriesMetadata (1)" and "Analyze book (1)" were both stuck. I can't remember if other type of tasks also had this problem happen, or if it's only those two types of tasks.

The issue seems to be a sql timeout at least according to the logs. I'm not sure why this timeout happens, but it seems to not be resolved and block everything other similar tasks: For example, i can do a library scans and new items will show up, but they won't be analyzed because the book analysis task is blocking all the other ones.

Expected behavior

I expect the tasks to either complete properly or to be killable without having to restart the server.

Actual behavior

The tasks block other similar tasks and go on forever (i let them run overnight for the most recent incident, for example), requiring a server restart to fix.

Logs

2025-05-19T18:28:49.397+02:00 ERROR 1 --- [scheduling-1] o.s.s.s.TaskUtils$LoggingErrorHandler    : Unexpected error occurred in scheduled task

org.jooq.exception.DataAccessException: SQL [select TASK.SIMPLE_TYPE, count(TASK.SIMPLE_TYPE) from TASK group by TASK.SIMPLE_TYPE]; SqliteTasksPool - Connection is not available, request timed out after 30000ms (total=1, active=1, idle=0, waiting=0)
	at org.jooq_3.19.15.SQLITE.debug(Unknown Source) ~[na:na]
	at org.jooq.impl.Tools.translate(Tools.java:3641) ~[jooq-3.19.15.jar:na]
	at org.jooq.impl.Tools.translate(Tools.java:3629) ~[jooq-3.19.15.jar:na]
	at org.jooq.impl.DefaultExecuteContext.sqlException(DefaultExecuteContext.java:827) ~[jooq-3.19.15.jar:na]
	at org.jooq.impl.AbstractQuery.execute(AbstractQuery.java:362) ~[jooq-3.19.15.jar:na]
	at org.jooq.impl.AbstractResultQuery.fetch(AbstractResultQuery.java:290) ~[jooq-3.19.15.jar:na]
	at org.jooq.impl.SelectImpl.fetch(SelectImpl.java:3232) ~[jooq-3.19.15.jar:na]
	at org.gotson.komga.infrastructure.jooq.tasks.TasksDao.countBySimpleType(TasksDao.kt:111) ~[application.jar:1.21.3]
	at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(Unknown Source) ~[na:na]
	at java.base/java.lang.reflect.Method.invoke(Unknown Source) ~[na:na]
	at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:359) ~[spring-aop-6.2.0.jar:6.2.0]
	at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:723) ~[spring-aop-6.2.0.jar:6.2.0]
	at org.gotson.komga.infrastructure.jooq.tasks.TasksDao$$SpringCGLIB$$0.countBySimpleType(<generated>) ~[application.jar:1.21.3]
	at org.gotson.komga.interfaces.sse.SseController.taskCount(SseController.kt:61) ~[application.jar:1.21.3]
	at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(Unknown Source) ~[na:na]
	at java.base/java.lang.reflect.Method.invoke(Unknown Source) ~[na:na]
	at org.springframework.scheduling.support.ScheduledMethodRunnable.runInternal(ScheduledMethodRunnable.java:130) ~[spring-context-6.2.0.jar:6.2.0]
	at org.springframework.scheduling.support.ScheduledMethodRunnable.lambda$run$2(ScheduledMethodRunnable.java:124) ~[spring-context-6.2.0.jar:6.2.0]
	at io.micrometer.observation.Observation.observe(Observation.java:499) ~[micrometer-observation-1.14.1.jar:1.14.1]
	at org.springframework.scheduling.support.ScheduledMethodRunnable.run(ScheduledMethodRunnable.java:124) ~[spring-context-6.2.0.jar:6.2.0]
	at org.springframework.scheduling.config.Task$OutcomeTrackingRunnable.run(Task.java:83) ~[spring-context-6.2.0.jar:6.2.0]
	at org.springframework.scheduling.support.DelegatingErrorHandlingRunnable.run(DelegatingErrorHandlingRunnable.java:54) ~[spring-context-6.2.0.jar:6.2.0]
	at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) ~[na:na]
	at java.base/java.util.concurrent.FutureTask.runAndReset(Unknown Source) ~[na:na]
	at java.base/java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(Unknown Source) ~[na:na]
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) ~[na:na]
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) ~[na:na]
	at java.base/java.lang.Thread.run(Unknown Source) ~[na:na]
Caused by: java.sql.SQLTransientConnectionException: SqliteTasksPool - Connection is not available, request timed out after 30000ms (total=1, active=1, idle=0, waiting=0)
	at com.zaxxer.hikari.pool.HikariPool.createTimeoutException(HikariPool.java:686) ~[HikariCP-5.1.0.jar:na]
	at com.zaxxer.hikari.pool.HikariPool.getConnection(HikariPool.java:179) ~[HikariCP-5.1.0.jar:na]
	at com.zaxxer.hikari.pool.HikariPool.getConnection(HikariPool.java:144) ~[HikariCP-5.1.0.jar:na]
	at com.zaxxer.hikari.HikariDataSource.getConnection(HikariDataSource.java:99) ~[HikariCP-5.1.0.jar:na]
	at org.springframework.jdbc.datasource.DataSourceUtils.fetchConnection(DataSourceUtils.java:160) ~[spring-jdbc-6.2.0.jar:6.2.0]
	at org.springframework.jdbc.datasource.DataSourceUtils.doGetConnection(DataSourceUtils.java:118) ~[spring-jdbc-6.2.0.jar:6.2.0]
	at org.springframework.jdbc.datasource.TransactionAwareDataSourceProxy$TransactionAwareInvocationHandler.invoke(TransactionAwareDataSourceProxy.java:247) ~[spring-jdbc-6.2.0.jar:6.2.0]
	at jdk.proxy2/jdk.proxy2.$Proxy133.prepareStatement(Unknown Source) ~[na:na]
	at org.jooq.impl.ProviderEnabledConnection.prepareStatement(ProviderEnabledConnection.java:109) ~[jooq-3.19.15.jar:na]
	at org.jooq.impl.SettingsEnabledConnection.prepareStatement(SettingsEnabledConnection.java:91) ~[jooq-3.19.15.jar:na]
	at org.jooq.impl.AbstractResultQuery.prepare(AbstractResultQuery.java:216) ~[jooq-3.19.15.jar:na]
	at org.jooq.impl.AbstractQuery.execute(AbstractQuery.java:315) ~[jooq-3.19.15.jar:na]
	... 23 common frames omitted

[komga.log](https://github.com/user-attachments/files/20300815/komga.log)

Komga version

1.21.3-MASTER

Operating system

Ubuntu 24.04.2 LTS

Installation method

Docker

Other details

This seems to happen when adding a lot of books at once. Since I like to synchronize my manga reading with anilist, i have my scans divided into chapters instead of books, so a long series will have hundred of chapters added all at once. Additionally, i have added more RAM to the docker image using JAVA_TOOL_OPTIONS=-Xmx4g; otherwise, apart from some disk bindings, all the options used for the docker image are the default ones.

Acknowledgements

  • [x] I have searched the existing issues (open AND closed) and this is a new ticket, NOT a duplicate or related to another open issue.
  • [x] I have written a short but informative title.
  • [x] I have checked the FAQ.
  • [x] I have updated the app to the latest version.
  • [x] I will fill out all of the requested information in this form.

hugoboissiere avatar May 19 '25 16:05 hugoboissiere

Classic problem of "Connection is not available, request timed out after 30000ms". Your hardware or disks or OS may be too slow.

gotson avatar May 20 '25 01:05 gotson

Any ways to test things to figure out which is causing the problem? Additionally, i think a good workaround for that blocking issue would be a restart server button, since restarting kills the blocking tasks. (i can always restart my docker container manually but having a dedicated button for it would be more convenient)

hugoboissiere avatar May 20 '25 17:05 hugoboissiere

i think a good workaround for that blocking issue would be a restart server button

there is a button to stop the server in Server Settings, it's tough to restart an app not knowing how exactly it runs though.

gotson avatar May 21 '25 01:05 gotson

Classic problem of "Connection is not available, request timed out after 30000ms". Your hardware or disks or OS may be too slow.

I am running komga on truenas scale via docker on 8 core nas with 64gb of ram with data on zfs raidz. Adding more cores (5 now) and more ram (8gb) does not make any change and I find that it hits this classic problem quite often when I try to add bigger number of volumes (at least higher than 20-30 volumes). It is not really viable for me to invest in ssd storage and I really don't feel that would solve that issue.

This issue is not really top priority as I can restart the app when this happens but it really could do file discovery more gracefully. Thanks for your work.

kayvax avatar Jul 06 '25 17:07 kayvax