Skip to content

Implement zealous block detection for HttpClient #10010

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

Merged
merged 6 commits into from
Nov 10, 2023
Merged

Implement zealous block detection for HttpClient #10010

merged 6 commits into from
Nov 10, 2023

Conversation

yawkat
Copy link
Member

@yawkat yawkat commented Oct 23, 2023

This new check throws an exception if any event loop thread would be blocked by a call to the netty BlockingHttpClient. This is usually a bug, as a blocked event loop can lose data.

However there are legitimate cases where this is fine, so there's also a config option to disable this detection. But all the cases in the micronaut-core test suite where this made a test fail were unintentional and potentially buggy, so most users should leave the setting as-is.

The error message provides two code remediation options. It also mentions that there's a config property for this, but doesn't explain which, because I want to discourage an "easy fix" that will leave the bug in place.

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
This new check throws an exception if *any* event loop thread would be blocked by a call to the netty BlockingHttpClient. This is usually a bug, as a blocked event loop can lose data.

However there are legitimate cases where this is fine, so there's also a config option to disable this detection. But all the cases in the micronaut-core test suite where this made a test fail were unintentional and potentially buggy, so most users should leave the setting as-is.

The error message provides two code remediation options. It also mentions that there's a config property for this, but doesn't explain which, because I want to discourage an "easy fix" that will leave the bug in place.
@yawkat yawkat added the type: enhancement New feature or request label Oct 23, 2023
@yawkat yawkat added this to the 4.2.0 milestone Oct 23, 2023

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
loop thread. This is a common cause for bugs: Event loops should \
never be blocked. You can either mark your controller as \
@ExecuteOn(TaskExecutors.BLOCKING), or use the reactive HTTP client \
to resolve this bug. There is also a configuration option to \
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
to resolve this bug. There is also a configuration option to \
to resolve this bug. There is also a configuration option micronaut.http.client.allow-block-event-loop=true to \

It also mentions that there's a config property for this, but doesn't explain which, because I want to discourage an "easy fix" that will leave the bug in place.

I don't agree with this. I think we should say which is the config property.

Copy link
Member Author

Choose a reason for hiding this comment

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

people will just enable the setting and move on without fixing their bug

Copy link
Contributor

Choose a reason for hiding this comment

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

I understand you are trying to encourage correct behavior.

However, we should not have secret properties they have to seek. If a setting exists, we have to document it. Let's say it is discouraged, and we can warn users about user it. But, we cannot expect our users to clone micronaut core and dive into our codebase to understand what is available.

Copy link
Member

Choose a reason for hiding this comment

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

Why not linking to a place in the docs where we explain why this is bad, and also document the property in a warning box?

Copy link
Contributor

@sdelamo sdelamo left a comment

Choose a reason for hiding this comment

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

@yawkat could solve the merge conflicts?

# Conflicts:
#	http-client/src/test/groovy/io/micronaut/http/client/BlockingSpec.groovy
@sdelamo
Copy link
Contributor

sdelamo commented Nov 10, 2023

@yawkat could solve the merge conflicts?

solved the merge.

Copy link

Please retry analysis of this Pull-Request directly on SonarCloud.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: enhancement New feature or request
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

None yet

5 participants