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

Provide BlockHound integration. #1637

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft

Provide BlockHound integration. #1637

wants to merge 2 commits into from

Conversation

johnrengelman
Copy link
Member

@johnrengelman johnrengelman commented Feb 26, 2022

Closes #1526


This change is Reviewable

@johnrengelman johnrengelman added this to the release-2.0.0 milestone Feb 26, 2022
@johnrengelman
Copy link
Member Author

I'm back and forth on where this class should actually exist. It probably shouldn't be used in production code, but maybe someone chooses to do that on purpose in like a test environment or something.
Netty dropped this into the netty-common library (https://github.com/netty/netty/pull/9687/files#diff-2652ecd7677e7e42648c274b05543377R75), which means its available and the user needs to add blockhound to the classpath to activate it. There's logic to that too.

builder.allowBlockingCallsInside("io.netty.channel.pool.SimpleChannelPool", "close");
builder.allowBlockingCallsInside("io.netty.channel.pool.FixedChannelPool", "close");
builder.allowBlockingCallsInside("ratpack.exec.internal.DefaultExecController", "close");
builder.allowBlockingCallsInside("ratpack.test.internal.BlockingHttpClient", "request");
Copy link

Choose a reason for hiding this comment

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

this is a very dangerous method to be allow-listed IMO, especially from the default integration.

Copy link
Member Author

Choose a reason for hiding this comment

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

The BlockingHttpClient one? That is only used for testing applications and not in production code.
the thing here is that it needs to block in order to do the async->sync transition in your tests.

Copy link

Choose a reason for hiding this comment

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

Judging by Netty, reactor-netty, reactor-kafka, and a number of other async non-blocking projects that integrated BlockHound, I can confidently say that testing of async code can be done without blocking calls in non-blocking threads, so maybe BlockHound is a red herring here?

Copy link
Member Author

Choose a reason for hiding this comment

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

Could be. I’ll dig deeper into this. Looking at it this should be called from the junit thread. I suspect maybe there is a test that is doing something wrong.
thansk for the feedback!

Copy link

Choose a reason for hiding this comment

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

Happy to help! That was my thinking as well - it is common to have blocking calls while testing non-blocking code, just from blocking-friendly threads. We were able to identify a couple of incorrectly handled context switches in reactor-kafka when we added BlockHound, where we assumed that it was safe to block, but apparently not. Your situation sounds very similar, and I hope it will be easy to identify the problematic code block 👍

Copy link

Choose a reason for hiding this comment

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

Copy link

Choose a reason for hiding this comment

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

builder.allowBlockingCallsInside("ratpack.test.internal.BlockingHttpClient", "request");

builder.nonBlockingThreadPredicate(current ->
t -> Execution.isManagedThread() ? Execution.isComputeThread() : current.test(t)
Copy link

Choose a reason for hiding this comment

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

My recommendation would be to have Execution.isManagedThread and Execution.isComputeThread accept Thread instances and provide overloads that use Thread.currentThread()

@jsalinaspolo
Copy link
Contributor

@johnrengelman, anything blocking this PR?
I was looking into it, but have some issues for blocking op/promise

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

BlockHound integration
3 participants