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

OpenAIClient causes "channel not registered to an event loop" error when receiving a 429 response status #43583

Open
robmartin-scibite opened this issue Dec 24, 2024 · 1 comment
Labels
customer-reported Issues that are reported by GitHub users external to the Azure organization. needs-triage Workflow: This is a new issue that needs to be triaged to the appropriate team. question The issue doesn't require a change to the product in order to be resolved. Most issues start as that

Comments

@robmartin-scibite
Copy link

robmartin-scibite commented Dec 24, 2024

Describe the bug
When using the OpenAIClient, if I call an endpoint which returns a 429 response with a body, I get an exception with error message channel not registered to an event loop.

Exception or Stack Trace
java.lang.IllegalStateException: channel not registered to an event loop

at io.netty.channel.AbstractChannel.eventLoop(AbstractChannel.java:163)
at com.azure.core.http.netty.implementation.NettyUtility.closeConnection(NettyUtility.java:79)
at com.azure.core.http.netty.implementation.NettyAsyncHttpResponse.close(NettyAsyncHttpResponse.java:116)
at com.azure.core.http.policy.RetryPolicy.attemptSync(RetryPolicy.java:249)
at com.azure.core.http.policy.RetryPolicy.processSync(RetryPolicy.java:161)
at com.azure.core.http.HttpPipelineNextSyncPolicy.processSync(HttpPipelineNextSyncPolicy.java:53)
at com.azure.core.http.policy.AddHeadersFromContextPolicy.processSync(AddHeadersFromContextPolicy.java:67)
at com.azure.core.http.HttpPipelineNextSyncPolicy.processSync(HttpPipelineNextSyncPolicy.java:53)
at com.azure.core.http.policy.RequestIdPolicy.processSync(RequestIdPolicy.java:77)
at com.azure.core.http.HttpPipelineNextSyncPolicy.processSync(HttpPipelineNextSyncPolicy.java:53)
at com.azure.core.http.policy.HttpPipelineSyncPolicy.processSync(HttpPipelineSyncPolicy.java:51)
at com.azure.core.http.policy.UserAgentPolicy.processSync(UserAgentPolicy.java:174)
at com.azure.core.http.HttpPipelineNextSyncPolicy.processSync(HttpPipelineNextSyncPolicy.java:53)
at com.azure.core.http.HttpPipeline.sendSync(HttpPipeline.java:138)
at com.azure.core.implementation.http.rest.SyncRestProxy.send(SyncRestProxy.java:62)
at com.azure.core.implementation.http.rest.SyncRestProxy.invoke(SyncRestProxy.java:83)
at com.azure.core.implementation.http.rest.RestProxyBase.invoke(RestProxyBase.java:124)
at com.azure.core.http.rest.RestProxy.invoke(RestProxy.java:95)
at jdk.proxy2/jdk.proxy2.$Proxy10.getChatCompletionsSync(Unknown Source)
at com.azure.ai.openai.implementation.OpenAIClientImpl.getChatCompletionsWithResponse(OpenAIClientImpl.java:1688)
at com.azure.ai.openai.OpenAIClient.getChatCompletionsWithResponse(OpenAIClient.java:329)
at com.azure.ai.openai.OpenAIClient.getChatCompletions(OpenAIClient.java:696)

To Reproduce
Use the code below against an endpoint which returns 429

Code Snippet

        OpenAIClientBuilder openAIClientBuilder = new OpenAIClientBuilder()
                .endpoint(<ENDOINT>)
                .credential(new KeyCredential(<KEY>))
                .serviceVersion(OpenAIServiceVersion.V2024_06_01);

        String tokens = IntStream.range(0, 10000)
                .mapToObj(Integer::toString)
                .collect(Collectors.joining(" "));

        OpenAIClient openAIClient = openAIClientBuilder.buildClient();
        ChatCompletionsOptions chatCompletionsOptions = new ChatCompletionsOptions(List.of(
                new ChatRequestSystemMessage("Count the tokens")
                , new ChatRequestUserMessage(tokens)));
       openAIClient.getChatCompletions(<DEPLOYMENT>, chatCompletionsOptions);

Expected behavior
The client to throw a suitable exception

@github-actions github-actions bot added customer-reported Issues that are reported by GitHub users external to the Azure organization. needs-triage Workflow: This is a new issue that needs to be triaged to the appropriate team. question The issue doesn't require a change to the product in order to be resolved. Most issues start as that labels Dec 24, 2024
@robmartin-scibite robmartin-scibite changed the title [BUG] RetryPolicy causes "channel not registered to an event loop" error for 429 with body Dec 24, 2024
@robmartin-scibite robmartin-scibite changed the title RetryPolicy causes "channel not registered to an event loop" error for 429 with body OpenAIClient causes "channel not registered to an event loop" error for 429 Dec 24, 2024
@robmartin-scibite
Copy link
Author

I think the above is a bug in com.azure.core.http.policy.RetryPolicy which on line 249 calls httpResponse.close() which attempts to close the response without reading the response body.
If I use the following retry policy everything works corrrectly:

ExponentialBackoffOptions exponentialBackoffOptions = new ExponentialBackoffOptions();
exponentialBackoffOptions.setMaxRetries(0);
RetryOptions retryOptions = new RetryOptions(exponentialBackoffOptions);

openAIClientBuilder.retryOptions(retryOptions);

@robmartin-scibite robmartin-scibite changed the title OpenAIClient causes "channel not registered to an event loop" error for 429 OpenAIClient causes "channel not registered to an event loop" error when receiving a 429 response status Dec 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
customer-reported Issues that are reported by GitHub users external to the Azure organization. needs-triage Workflow: This is a new issue that needs to be triaged to the appropriate team. question The issue doesn't require a change to the product in order to be resolved. Most issues start as that
Projects
None yet
Development

No branches or pull requests

1 participant