IllegalStateException: closed, at okio.RealBufferedSource

We have encountered the following exception while fetching positions using zerodha kite java client library.


java.lang.IllegalStateException: closed
at okhttp3.internal.Util.readBomAsCharset(Util.kt:256)
at okhttp3.ResponseBody.string(ResponseBody.kt:187)
at com.zerodhatech.kiteconnect.kitehttp.KiteResponseHandler.handle(
at com.zerodhatech.kiteconnect.kitehttp.KiteRequestHandler.getRequest(
at com.zerodhatech.kiteconnect.KiteConnect.getPositions(

Now, searching for similar forum posts in the past, the suggestion is to retry and it may succeed.
While this may be true for cases where we are "fetching" some data, but I have a concern for case such as below,

1/ We place a BUY/SELL order
2/ Zerodha places order at NSE
3/ While returning response, Zerodha encounters some issue and throws exception back to user
4/ Now, if user catches the exception and retries, he would start placing duplicate orders (which may even succeed if margin is available)

How do we handle such dangerous case?
Can anyone kindly respond why this issue happens and how do we handle it?
Sign In or Register to comment.