When I use the line kiteConnect.generateSession(requestToken, api_secret) in my code, it spaws OKHttp taskrunner and UrlChecker threads that die out after exactly 5 minutes after the execution of the above mentioned line of code. When the program runs long (places orders and receives web ticker), these threads dont die at all which raises the issue of the clean exit of my program. Can you please guide a little on how these threads are supposed to work, how is their ttyl decided and how can I manage them to do a clean exit of my code?
Here is the output of uname -a : Linux PC 5.9.2-arch1-1 #1 SMP PREEMPT Thu, 29 Oct 2020 17:01:28 +0000 x86_64 GNU/Linux Here is the output of java --version : openjdk 14.0.2 2020-07-14 OpenJDK Runtime Environment (build 14.0.2+12) OpenJDK 64-Bit Server VM (build 14.0.2+12, mixed mode)
I created a new project with the following maven dependency to make sure I wasnt using the old libraries :
If you look at the runtime in the attached image in my previous reply, its from 10:35:49 to 10:40:50. If I use proper logging, this time is always exactly 5 minutes.
KiteRequestHandler class has the OkHttpClient which is used to make requests and that is created only once and reused. Can you try to fork javakiteconnect and try calling client.getDispatcher().getExecutorService().shutdown(); once you are done?
Which version of javakiteconnect are you using?
This unclean exit shouldn't be there on our latest version.
OkHttp TaskRunner
OkHttp api.kite.trade
OkHttp TaskRunner
Okio Watchdog
OkHttp TaskRunner
Code :
Linux PC 5.9.2-arch1-1 #1 SMP PREEMPT Thu, 29 Oct 2020 17:01:28 +0000 x86_64 GNU/Linux
Here is the output of java --version :
openjdk 14.0.2 2020-07-14
OpenJDK Runtime Environment (build 14.0.2+12)
OpenJDK 64-Bit Server VM (build 14.0.2+12, mixed mode)
I created a new project with the following maven dependency to make sure I wasnt using the old libraries :
<code class="CodeInline">
<!-- https://mvnrepository.com/artifact/com.zerodhatech.kiteconnect/kiteconnect -->
<dependency>
<groupId>com.zerodhatech.kiteconnect</groupId>
<artifactId>kiteconnect</artifactId>
<version>3.1.3</version>
</dependency>
Does the testbar() which I wrote above reproduce the issue at your end?
Can you try to fork javakiteconnect and try calling
client.getDispatcher().getExecutorService().shutdown();
once you are done?source: https://github.com/square/okhttp/issues/1739
https://github.com/zerodha/javakiteconnect/blob/master/kiteconnect/src/com/zerodhatech/kiteconnect/kitehttp/KiteRequestHandler.java#L84
https://github.com/zerodha/javakiteconnect/blob/master/kiteconnect/src/com/zerodhatech/kiteconnect/kitehttp/KiteResponseHandler.java#L16
Read the 'execute' method documentation:
https://github.com/square/okhttp/blob/ee1ba4656d80ed62485387217271c7fa31dc888e/okhttp/src/jvmMain/kotlin/okhttp3/Call.kt#L28
Can you please fix this. It makes it difficult to do testing & manage program lifecycle.