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

Avoid catch (Throwable t) in AmazonBedrockStreamingChatProcessor #115715

Conversation

DaveCTurner
Copy link
Contributor

CompletableFuture.runAsync implicitly catches all Throwable
instances thrown by the task, which includes Error instances that no
reasonable application should catch. Moreover, discarding the return
value from these methods means that any such Error will be ignored,
allowing the JVM to carry on running in an invalid state.

This commit replaces these trappy calls with more appropriate exception
handling.

`CompletableFuture.runAsync` implicitly catches all `Throwable`
instances thrown by the task, which includes `Error` instances that no
reasonable application should catch. Moreover, discarding the return
value from these methods means that any such `Error` will be ignored,
allowing the JVM to carry on running in an invalid state.

This commit replaces these trappy calls with more appropriate exception
handling.
@DaveCTurner DaveCTurner added >bug :ml Machine learning auto-backport Automatically create backport pull requests when merged v9.0.0 v8.16.1 v8.17.0 labels Oct 26, 2024
@DaveCTurner DaveCTurner requested a review from prwhelan October 26, 2024 09:44
@elasticsearchmachine elasticsearchmachine added the Team:ML Meta label for the ML team label Oct 26, 2024
@elasticsearchmachine
Copy link
Collaborator

Pinging @elastic/ml-core (Team:ML)

@elasticsearchmachine
Copy link
Collaborator

Hi @DaveCTurner, I've created a changelog YAML for you.

Copy link
Member

@prwhelan prwhelan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for catching this

try {
threadPool.executor(UTILITY_THREAD_POOL_NAME).execute(runnable);
} catch (Exception e) {
logger.error(Strings.format("failed to fork [%s] to utility thread pool", runnable), e);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We probably should have been handling the exception - I didn't think to do that initially, but seeing it explicitly caught like this is making me think we should

Suggested change
logger.error(Strings.format("failed to fork [%s] to utility thread pool", runnable), e);
logger.error(Strings.format("failed to fork [%s] to utility thread pool", runnable), e);
cancel();
onError(e);

We can either include that here (and I can follow up with a unit test) or I can follow up with that change outside of this one.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll leave that for you to do in a followup. In practice we can't really throw an exception here anyway because of how the UTILITY_THREAD_POOL_NAME executor is configured today.

@DaveCTurner DaveCTurner merged commit a1670c1 into elastic:main Oct 28, 2024
16 checks passed
@DaveCTurner DaveCTurner deleted the 2024/10/26/AmazonBedrockStreamingChatProcessor-CompletableFuture branch October 28, 2024 15:32
DaveCTurner added a commit to DaveCTurner/elasticsearch that referenced this pull request Oct 28, 2024
…lastic#115715)

`CompletableFuture.runAsync` implicitly catches all `Throwable`
instances thrown by the task, which includes `Error` instances that no
reasonable application should catch. Moreover, discarding the return
value from these methods means that any such `Error` will be ignored,
allowing the JVM to carry on running in an invalid state.

This commit replaces these trappy calls with more appropriate exception
handling.
DaveCTurner added a commit to DaveCTurner/elasticsearch that referenced this pull request Oct 28, 2024
…lastic#115715)

`CompletableFuture.runAsync` implicitly catches all `Throwable`
instances thrown by the task, which includes `Error` instances that no
reasonable application should catch. Moreover, discarding the return
value from these methods means that any such `Error` will be ignored,
allowing the JVM to carry on running in an invalid state.

This commit replaces these trappy calls with more appropriate exception
handling.
@elasticsearchmachine
Copy link
Collaborator

💚 Backport successful

Status Branch Result
8.16
8.x

elasticsearchmachine pushed a commit that referenced this pull request Oct 28, 2024
…115715) (#115790)

`CompletableFuture.runAsync` implicitly catches all `Throwable`
instances thrown by the task, which includes `Error` instances that no
reasonable application should catch. Moreover, discarding the return
value from these methods means that any such `Error` will be ignored,
allowing the JVM to carry on running in an invalid state.

This commit replaces these trappy calls with more appropriate exception
handling.
elasticsearchmachine pushed a commit that referenced this pull request Oct 28, 2024
…115715) (#115789)

`CompletableFuture.runAsync` implicitly catches all `Throwable`
instances thrown by the task, which includes `Error` instances that no
reasonable application should catch. Moreover, discarding the return
value from these methods means that any such `Error` will be ignored,
allowing the JVM to carry on running in an invalid state.

This commit replaces these trappy calls with more appropriate exception
handling.
ioanatia pushed a commit to ioanatia/elasticsearch that referenced this pull request Nov 4, 2024
…lastic#115715)

`CompletableFuture.runAsync` implicitly catches all `Throwable`
instances thrown by the task, which includes `Error` instances that no
reasonable application should catch. Moreover, discarding the return
value from these methods means that any such `Error` will be ignored,
allowing the JVM to carry on running in an invalid state.

This commit replaces these trappy calls with more appropriate exception
handling.
jfreden pushed a commit to jfreden/elasticsearch that referenced this pull request Nov 4, 2024
…lastic#115715)

`CompletableFuture.runAsync` implicitly catches all `Throwable`
instances thrown by the task, which includes `Error` instances that no
reasonable application should catch. Moreover, discarding the return
value from these methods means that any such `Error` will be ignored,
allowing the JVM to carry on running in an invalid state.

This commit replaces these trappy calls with more appropriate exception
handling.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
auto-backport Automatically create backport pull requests when merged >bug :ml Machine learning Team:ML Meta label for the ML team v8.16.1 v8.17.0 v9.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants