I am encountering an issue in my Spring Boot application where I am using WebClient to make synchronous calls to a remote service. However, when I use the block() method to wait for the WebClient response, I have observed that Unsafe.park takes too much time to execute and it keeps on increasing with subsequent calls. This occurs intermittently and seems to be related to thread contention or deadlock.In some cases, this Unsafe.park keeps on exceuting for more than 1 minute, causing significant delays in my application.
Here's a simplified version of my code:
Root uploadedFile = WebClient.builder().build().post().uri(uri)
.contentType(MediaType.APPLICATION_JSON)
.header("Authorization", apiKey)
.body(BodyInserters.fromMultipartData(map))
.retrieve()
.bodyToMono(Root.class)
.block(); // <-- Issue occurs here
The block() method seems to be causing the main thread to park indefinitely, resulting in the Unsafe.park issue. This problem occurs sporadically and is difficult to reproduce consistently.
Are there any known issues or best practices related to using block() with WebClient in Spring Boot applications? Any suggestions or insights on how to troubleshoot and resolve this issue would be greatly appreciated. Thank you!
#retrieve
, such that#block
is simply waiting for another signal that will never arrive? – Numbskullblock
does block the thread but felt the need to invent the phrase “Unsafe.park issues” for the situation? – Meddlepark()
is the backend of almost every method of the concurrency APIs that may block or wait for some time. Everything belowblockingGet
is an irrelevant implementation detail. You see that a method namedblockingGet
is blocking, which sounds like expected behavior given the name. Is it blocking too much or too long? Well, only you can tell. So far, you didn’t say that you have an actual performance or latency issue, only those “Unsafe.park issues”. – Meddlem.foo().bar()
, you'd haven = m.foo(); n.bar();
)? – Numbskull