Skip to content

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

Open
@robmartin-scibite

Description

@robmartin-scibite

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

Metadata

Metadata

Labels

OpenAIcustomer-reportedIssues that are reported by GitHub users external to the Azure organization.questionThe issue doesn't require a change to the product in order to be resolved. Most issues start as that

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions