Skip to content

Infinite loop in in AbstractBedrockApi responseHandler.onComplete() #1633

@Planview-JamesK

Description

@Planview-JamesK

Bug description
When a subscribed exception handler itself throws exceptions, the AbstractBedrockApi will infinitely try to complete the stream.

Environment
Spring AI 1.0.0-snapshot
openjdk 17.0.13 2024-10-15

Steps to reproduce
Create a Flux stream like so:
Anthropic3ChatBedrockApi api = new Anthropic3ChatBedrockApi(...); api.chatCompletionStream(request).subscribe(response -> { throw NullPointerException("some error1"); }, ex -> throw NullPointerException("some error2") ), () -> throw NullPointerException("some error3") );

Expected behavior
I'd expect an exception to be thrown.

Instead, I see
Emitting complete:FAIL_TERMINATED
output to console very rapidly and infinitely

This is because of the while loop in AbstractBedrockApi.internalInvocationStream() never meeting its exit condition.
If an errorHandler throws an exception persistently, this can take down a service depending on what else the error handler is doing, there should be a circuit breaker that terminates the Flux stream.

Metadata

Metadata

Assignees

Labels

BedrockbugSomething isn't working

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions