-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Permit reentrant use of ReactiveByteBufferByteBody.SharedBuffer (#11589)
This is in line with the netty implementation and required to fix deadlocks in servlet due to blocking calls.
- Loading branch information
Showing
2 changed files
with
50 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
http/src/test/java/io/micronaut/http/body/ReactiveByteBufferByteBodyTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package io.micronaut.http.body; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.Timeout; | ||
import reactor.core.publisher.Sinks; | ||
|
||
import java.io.IOException; | ||
import java.nio.ByteBuffer; | ||
import java.nio.charset.StandardCharsets; | ||
import java.util.concurrent.CompletableFuture; | ||
import java.util.concurrent.ExecutionException; | ||
|
||
class ReactiveByteBufferByteBodyTest { | ||
@Test | ||
@Timeout(10) | ||
public void reentrancy() throws ExecutionException, InterruptedException { | ||
// reentrant subscribe inside onComplete handler. servlet uses this pattern | ||
Sinks.One<ByteBuffer> sink = Sinks.one(); | ||
try (ReactiveByteBufferByteBody body = ByteBufferBodyAdapter.adapt(sink.asMono())) { | ||
CompletableFuture<byte[]> result = new CompletableFuture<>(); | ||
InternalByteBody.bufferFlow(body.split(ByteBody.SplitBackpressureMode.FASTEST)).onComplete((cabb, e) -> { | ||
if (e != null) { | ||
result.completeExceptionally(e); | ||
return; | ||
} | ||
cabb.close(); | ||
try { | ||
result.complete(body.toInputStream().readAllBytes()); | ||
} catch (IOException ex) { | ||
result.completeExceptionally(ex); | ||
} | ||
}); | ||
sink.tryEmitValue(ByteBuffer.wrap("Hello".getBytes(StandardCharsets.UTF_8))).orThrow(); | ||
result.get(); | ||
} | ||
} | ||
} |