Ktor client (Apache) seems to have got into a bad ...
# ktor
j
Ktor client (Apache) seems to have got into a bad state - any likely causes? Stacktrace attached.
Copy code
java.lang.IllegalStateException: Request cannot be executed; I/O reactor status: STOPPED
 	at org.apache.http.util.Asserts.check(Asserts.java:46)
 	at org.apache.http.impl.nio.client.CloseableHttpAsyncClientBase.ensureRunning(CloseableHttpAsyncClientBase.java:90)
 	at org.apache.http.impl.nio.client.InternalHttpAsyncClient.execute(InternalHttpAsyncClient.java:123)
 	at org.apache.http.impl.nio.client.CloseableHttpAsyncClient.execute(CloseableHttpAsyncClient.java:68)
 	at io.ktor.client.engine.apache.ApacheHttpRequestKt.sendRequest(ApacheHttpRequest.kt:50)
 	at io.ktor.client.engine.apache.ApacheEngine.execute(ApacheEngine.kt:23)
 	at io.ktor.client.engine.HttpClientEngine$install$1.invokeSuspend(HttpClientEngine.kt:49)
 	at io.ktor.client.engine.HttpClientEngine$install$1.invoke(HttpClientEngine.kt)
 	at io.ktor.util.pipeline.SuspendFunctionGun.loop(PipelineContext.kt:268)
No obvious logging to suggest anything was closing down. Ktor version 1.2.4
r
I've had that too but never figured out why it was happening.
Not having time to debug that, I ended up switching to the CIO client. Which has its own issues but seems to generally work well.
j
Thanks @rocketraman, this is the first time I've seen it, but haven't been using it long. That makes me a bit nervous about using the Apache client in production - anyone got any idea what could have happened?
I was assuming the Apache client would be pretty well tested and widely used
r
If you google that error, all you really find is that the Apache client should never get into that state. So its almost certainly a problem with how Ktor is using it.
I've used the Apache client on its own pretty extensively and never had that issue.
j
Yeah, likewise - would be interested in hearing from people who do use the Apache client, or whether others have hit the same error.
Can't see an open issue on Github either
e
Hi @Jonathan Mew, it usually happens when the client is canceled or closed, but there are pending requests there.
Could you file an issue?
j
Yeah, no problem
thanks
https://github.com/ktorio/ktor/issues/1449 Apologies if I'm just using the client in an unintended way or something
Ugh. Was just me being stupid 😞 closed the issue
r
> I had passed an HttpClient instance rather than the provider and was trying to reuse a single instance. Just curious: into what? The
Apache
object into the
HttpClient
constructor function?
j
I have a DAO and pass it a client provider lambda. It creates a client while handling a particular request and uses it to make one request itself (calling httpClient.use{}, which closes the client). I pass the lambda at construction so that test instances can use a test HttpClient implementation which doesn't send any request. But instead of passing the provider, I passed the instance - a refactoring fail. But the client would work for one call, so wasn't immediately obvious it was broken.
r
Ah ok, thanks for the explanation. I don't believe that was my situation, but since I haven't used the Apache client in months, I'd have to go spelunking through our git history to check.