https://kotlinlang.org logo
#ktor
Title
# ktor
j

Jonathan Mew

11/18/2019, 2:29 PM
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

rocketraman

11/18/2019, 2:39 PM
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

Jonathan Mew

11/18/2019, 2:43 PM
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

rocketraman

11/18/2019, 2:44 PM
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

Jonathan Mew

11/18/2019, 2:53 PM
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

e5l

11/18/2019, 3:04 PM
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

Jonathan Mew

11/18/2019, 3:04 PM
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

rocketraman

11/19/2019, 3:47 PM
> 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

Jonathan Mew

11/19/2019, 3:53 PM
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

rocketraman

11/19/2019, 3:55 PM
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.
2 Views