Loop infinity
Colerar opened this issue · comments
Welcome with your first issue
Hello and thankk you for your issue. I will take a look this problem asap, thanks for reproducing sample
Hi again. @Colerar I have tested your case and found next points:
- Default context of
runBlocking
(as well as insuspend main
) do not handle delays correctly. I have created next test and it was working just as you described:
@Test
fun simple() {
runTest {
doInfinity("0 0 8 /3 *") {
println(it)
}
}
}
- But them I have added normal coroutine scope and you sample was working correctly:
@Test
fun simple() {
runTest {
CoroutineScope(Dispatchers.Default).launch {
doInfinity("0 0 8 /3 *") {
println(it)
}
}.join()
}
}
So, it looks like the coroutine scope of runBlocking
(and suspend main
) is not suitable at least for correct handling of delay
s
Anyway, I would like to know, how will work the next code for you:
suspend main() {
CoroutineScope(Dispatchers.Default).launch {
doInfinity("0 0 8 /3 *") {
println(it)
}
}.join()
}
Please, close this issue or at least comment with the results of your try :) (anyway thank you for that issue, I get know something new)
Hello :) I have checked one more time the next sample (ready for copy-paste in clear gradle project with kotlin 1.8.21
and krontab 2.1.1
):
import dev.inmo.krontab.doInfinity
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
suspend fun main() {
CoroutineScope(Dispatchers.Default).launch {
doInfinity("0 0 8 /3 *") {
println(it)
}
}.join()
}
So, this sample used approximately 0% of CPU and 15-20 mB RAM (I think, it can be related to profiler attachment). Anyway, could you please write your version of kotlin, library, java and some other environment. It may help me to catch the error
Yes, I set time to 2023-06-28 19:58 UTC, run the sample code, this issue can always be reproduce. Gradle version catalog:
[versions]
kotlin = "1.8.22"
[libraries]
krontab = "dev.inmo:krontab:2.1.1"
Hello and thank you :) what about java and OS on your device?
Repo: https://github.com/Colerar/krontab-loop-issue
macOS 13 with JDK 8/11/17:
❯ java -jar ./app/build/libs/app-all.jar
OS: Mac OS X-x86_64-13.4.1
JVM: 1.8-Azul Systems, Inc.
Current system time: 2023-06-28T16:04:07.450Z
Running krontab...
[0] Free mem = 242660640
[1] Free mem = 201971648
[2] Free mem = 598024240
[3] Free mem = 531433432
[4] Free mem = 246059624
[5] Free mem = 454519496
[6] Free mem = 343614016
^C%
~/Developer/krontab-loop-issue main
❯ jenv local 11.0
~/Developer/krontab-loop-issue main
❯ java -jar ./app/build/libs/app-all.jar
OS: Mac OS X-x86_64-13.4.1
JVM: 11-Azul Systems, Inc.
Current system time: 2023-06-28T16:04:24.759256Z
Running krontab...
[0] Free mem = 262150776
[1] Free mem = 111876320
[2] Free mem = 122379912
[3] Free mem = 163864016
[4] Free mem = 147613136
[5] Free mem = 149710288
[6] Free mem = 157911616
[7] Free mem = 206612928
[8] Free mem = 208350224
[9] Free mem = 208430544
[10] Free mem = 165403800
[11] Free mem = 148638152
^C%
❯ jenv local 17.0
❯ java -jar ./app/build/libs/app-all.jar
OS: Mac OS X-x86_64-13.4.1
JVM: 17-Azul Systems, Inc.
Current system time: 2023-06-28T16:04:41.784230Z
Running krontab...
[0] Free mem = 264992536
[1] Free mem = 173393288
[2] Free mem = 167093664
[3] Free mem = 223061984
[4] Free mem = 182402168
[5] Free mem = 261964328
[6] Free mem = 194183888
[7] Free mem = 251800792
[8] Free mem = 148153992
[9] Free mem = 243549192
[10] Free mem = 147115272
[11] Free mem = 267745528
[12] Free mem = 166027272
^C%
Windows 10 JDK 17:
❯ java -jar app-all.jar
OS: Windows 10-amd64-10.0
JVM: 17-Azul Systems, Inc.
Current system time: 2023-06-28T16:08:12.379654300Z
Running krontab...
[0] Free mem = 127924224
[1] Free mem = 132113312
[2] Free mem = 179811208
[3] Free mem = 196652496
[4] Free mem = 204693480
[5] Free mem = 88422488
[6] Free mem = 190212976
[7] Free mem = 167195400
[8] Free mem = 163496888
[9] Free mem = 113208424
[10] Free mem = 165167088
[11] Free mem = 94921616
[12] Free mem = 143686328
[13] Free mem = 184577464
Ubuntu 22 JDK 17:
❯ java -jar app-all.jar
OS: Linux-amd64-5.15.0-40-generic
JVM: 17-Private Build
Current system time: 2023-06-28T16:13:01.109962981Z
Running krontab...
[0] Free mem = 60850176
[1] Free mem = 109445616
[2] Free mem = 125168080
[3] Free mem = 149282768
[4] Free mem = 71690192
[5] Free mem = 119216768
[6] Free mem = 108676520
[7] Free mem = 106291152
[8] Free mem = 163912952
[9] Free mem = 83226592
[10] Free mem = 89513936
[11] Free mem = 167618656
[12] Free mem = 137210616
I think this issue is not related to system or JDK version.
Ok, could you please share your sample project with this issue?
Ok, could you please share your sample project with this issue?
Yes there is a link to the sample project in my last comment:
Runned with ./gradlew run
:
> Task :app:run
OS: Linux-amd64-6.3.9-060309-generic
JVM: 1.8-Temurin
Current system time: 2023-07-17T12:17:35.074Z
Running krontab...
[0] Free mem = 231833200
[1] Free mem = 225431528
[2] Free mem = 225431528
[3] Free mem = 225431528
[4] Free mem = 225431528
[5] Free mem = 225431528
[6] Free mem = 225431528
[7] Free mem = 225431528
[8] Free mem = 225431528
[9] Free mem = 225431528
[10] Free mem = 225431528
[11] Free mem = 225431528
[12] Free mem = 225431528
[13] Free mem = 225431528
[14] Free mem = 225431528
[15] Free mem = 225431528
[16] Free mem = 225431528
[17] Free mem = 225431528
[18] Free mem = 225431528
[19] Free mem = 225431528
[20] Free mem = 225431528
[21] Free mem = 225431528
[22] Free mem = 225431528
[23] Free mem = 225431528
[24] Free mem = 225431528
[25] Free mem = 225431528
Runned with application startup:
krontab-loop-issue/app/build/distributions/app-shadow/bin$ ./app
OS: Linux-amd64-6.3.9-060309-generic
JVM: 17-BellSoft
Current system time: 2023-07-17T12:20:35.890791921Z
Running krontab...
[0] Free mem = 254478600
[1] Free mem = 250045616
[2] Free mem = 250045616
[3] Free mem = 250045616
[4] Free mem = 250045616
[5] Free mem = 250045616
[6] Free mem = 250045616
[7] Free mem = 250045616
[8] Free mem = 250045616
[9] Free mem = 250045616
[10] Free mem = 250045616
[11] Free mem = 250045616
And run with java -jar
:
krontab-loop-issue/app/build/libs$ java -jar app-all.jar
OS: Linux-amd64-6.3.9-060309-generic
JVM: 17-BellSoft
Current system time: 2023-07-17T12:22:51.898114307Z
Running krontab...
[0] Free mem = 254023096
[1] Free mem = 249621720
[2] Free mem = 249621720
[3] Free mem = 249621720
[4] Free mem = 249621720
[5] Free mem = 249621720
[6] Free mem = 249621720
[7] Free mem = 249621720
[8] Free mem = 249621720
[9] Free mem = 249621720
[10] Free mem = 249621720
This problem is related to system time. So we need to set time to about 2023-06-28T16:00:00Z to reproduce it. :)
This problem is related to system time. So we need to set time to about 2023-06-28T16:00:00Z to reproduce it. :)
Could you please change the sample git repo to guarantee reproducing of bug? I am steel unable to catch it
Closing according to inactivity and potentially exists fix