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

[Bug] HttpTimeout does not work for SSE connection #4682

Closed
hehua2008 opened this issue Feb 18, 2025 · 3 comments · Fixed by #4687
Closed

[Bug] HttpTimeout does not work for SSE connection #4682

hehua2008 opened this issue Feb 18, 2025 · 3 comments · Fixed by #4687

Comments

@hehua2008
Copy link
Contributor

I have configured HttpClient with

            install(HttpTimeout) {
                connectTimeoutMillis = 60_000
                requestTimeoutMillis = 60_000
                socketTimeoutMillis = 180_000
            }

but it does not work for SSE connection.

I checked the source code and found:

public val HttpTimeout: ClientPlugin<HttpTimeoutConfig> = createClientPlugin(
    "HttpTimeout",
    ::HttpTimeoutConfig
) {
    // ...
    on(Send) { request ->
        val isWebSocket = request.url.protocol.isWebsocket()
        if (isWebSocket ||
            request.body is ClientUpgradeContent ||
            request.body is SSEClientContent
        ) {
            return@on proceed(request)
        }

        var configuration = request.getCapabilityOrNull(HttpTimeoutCapability)
        if (configuration == null && hasNotNullTimeouts()) {
            configuration = HttpTimeoutConfig()
            request.setCapability(HttpTimeoutCapability, configuration)
        }
    // ...
}

I have no idea why Ktor skip setting HttpTimeoutConfig for SEE connection ???

I need a long timeout to get SSE response from LLM AI cloud service. A default timeout value of 10 seconds of OkHttpClient used in Ktor is too small for LLM AI cloud service. Some LLM AI cloud service may take more than 10 seconds to generate next response.

So, is this a bug and should be fixed ?
Or will there be a more reasonable solution ?

@marychatte
Copy link
Member

We don't set HttpTimeout for SSE requests at all. It's a bug only for the OkHttp engine, I will take a look at it

@marychatte
Copy link
Member

@hehua2008 The issue will be fixed here: #4687

@hehua2008
Copy link
Contributor Author

@hehua2008 The issue will be fixed here: #4687

Thank you very much!😆

@osipxd osipxd linked a pull request Feb 20, 2025 that will close this issue
@osipxd osipxd closed this as completed Feb 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants