Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Non-blocking HTTP with this library? #1197

Closed
Mygod opened this issue Jun 24, 2019 · 1 comment
Closed

Non-blocking HTTP with this library? #1197

Mygod opened this issue Jun 24, 2019 · 1 comment
Assignees
Labels

Comments

@Mygod
Copy link

Mygod commented Jun 24, 2019

Ktor Version

1.2.2

Ktor Engine Used(client or server and name)

client CIO or Apache

JVM Version, Operating System and Relevant Context

Android 9

Feedback

I am trying to do non-blocking IO (testing via doing network on main thread on Android and see where NetworkOnMainThreadException occurs), however, both CIO and Apache seems to fail in doing DNS resolving.

Is it possible or planned to implement completely non-blocking HTTP requests?

CIO

In CIO, the main thread attempts to resolve DNS at io.ktor.client.engine.cio.Endpoint.(Endpoint.kt:29).
I don't think there is any way to get around that.

Apache

Similar thing happens to Apache. I found that there is a way to customize DnsResolver like such:

HttpClient(Apache) {
    engine {
        customizeClient {
            setConnectionManager(PoolingNHttpClientConnectionManager(
                    DefaultConnectingIOReactor(IOReactorConfig.DEFAULT),
                    null
            ) { InetAddress.getAllByName(it) })
        }
    }
}

Unfortunately, apache DnsResolver does not support suspend/async calls, so sadly I cannot take advantage of new nonblocking API provided by Android API 29.

@e5l
Copy link
Member

e5l commented Jun 4, 2020

Hi, @Mygod. Thanks for the question.
We have no async DNS right now. I made the separate issue for that: #1924

@e5l e5l closed this as completed Jun 4, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants