Uncomment buffer leak tests in DataBufferUtils

Following a response on
https://github.com/reactor/reactor-core/issues/1634 apparently
FluxSink is respecting doOnDiscard but there is a race condition
in DataBufferUtils with file reading.

This commit makes two changes:
1) Add more checks for onDispose to detect cancellation signals
as well as to deal with potentially concurrent such signal.
2) Do not close the channel through the Flux.using callback but
rather allow the current I/O callback to take place and only then
close the channel or else the buffer is left hanging.

Despite this tests still can fail due to a suspected issue in Reactor
itself with the doOnDiscard callback for FluxSink. That's tracked under
the same issue https://github.com/reactor/reactor-core/issues/1634
and for now the use of DefaultDataBufferFactory is enforced as a
workaround until the issue is resolved.

See gh-22107
This commit is contained in:
Rossen Stoyanchev
2019-03-28 17:18:40 -04:00
parent 3cf2c04406
commit beae1fbb12
5 changed files with 38 additions and 16 deletions

View File

@@ -80,8 +80,7 @@ public class ResourceRegionEncoderTests {
.expectComplete()
.verify();
// TODO: https://github.com/reactor/reactor-core/issues/1634
// this.bufferFactory.checkForLeaks();
this.bufferFactory.checkForLeaks();
}
@Test
@@ -122,11 +121,10 @@ public class ResourceRegionEncoderTests {
.expectComplete()
.verify();
// TODO: https://github.com/reactor/reactor-core/issues/1634
// this.bufferFactory.checkForLeaks();
this.bufferFactory.checkForLeaks();
}
@Test // gh-
@Test // gh-22107
public void cancelWithoutDemandForMultipleResourceRegions() {
Resource resource = new ClassPathResource("ResourceRegionEncoderTests.txt", getClass());
Flux<ResourceRegion> regions = Flux.just(
@@ -173,8 +171,7 @@ public class ResourceRegionEncoderTests {
.expectError(EncodingException.class)
.verify();
// TODO: https://github.com/reactor/reactor-core/issues/1634
// this.bufferFactory.checkForLeaks();
this.bufferFactory.checkForLeaks();
}
protected Consumer<DataBuffer> stringConsumer(String expected) {

View File

@@ -135,6 +135,7 @@ public abstract class AbstractDataBufferAllocatingTestCase {
catch (InterruptedException ex) {
// ignore
}
continue;
}
assertEquals("ByteBuf Leak: " + total + " unreleased allocations", 0, total);
}

View File

@@ -187,8 +187,6 @@ public class DataBufferUtilsTests extends AbstractDataBufferAllocatingTestCase {
.verify();
}
// TODO: Remove ignore after https://github.com/reactor/reactor-core/issues/1634
@Ignore
@Test // gh-22107
public void readAsynchronousFileChannelCancelWithoutDemand() throws Exception {
URI uri = this.resource.getURI();

View File

@@ -85,6 +85,7 @@ public class LeakAwareDataBufferFactory implements DataBufferFactory {
catch (InterruptedException ex) {
// ignore
}
continue;
}
List<AssertionError> errors = this.created.stream()
.filter(LeakAwareDataBuffer::isAllocated)