Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ public class AsyncFileImpl implements AsyncFile {
}
this.context = context;
this.queue = new InboundBuffer<>(context, 0);
queue.exceptionHandler(context::reportException);
queue.handler(buff -> {
if (buff.length() > 0) {
handleBuffer(buff);
Expand Down
35 changes: 35 additions & 0 deletions vertx-core/src/test/java/io/vertx/tests/file/FileSystemTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
import io.vertx.core.internal.buffer.BufferInternal;
import io.vertx.core.file.impl.AsyncFileImpl;
import io.vertx.core.impl.Utils;
import io.vertx.core.internal.ContextInternal;
import io.vertx.core.internal.VertxInternal;
import io.vertx.core.json.JsonObject;
import io.vertx.core.streams.ReadStream;
import io.vertx.test.core.TestUtils;
Expand All @@ -38,6 +40,7 @@
import java.nio.channels.OverlappingFileLockException;
import java.nio.file.*;
import java.nio.file.attribute.*;
import java.util.ArrayList;
import java.util.EnumSet;
import java.util.HashSet;
import java.util.List;
Expand Down Expand Up @@ -2314,4 +2317,36 @@ public void testClosedAsyncFileSetNullHandler() throws Exception {
asyncFile.drainHandler(null);
asyncFile.endHandler(null);
}

@Test
public void testAsyncFileHandlerFailuresAreReportedToContext() throws Exception {
String fileName = "file.txt";
createFileWithJunk(fileName, 100);
RuntimeException dataFailure = new RuntimeException("data");
RuntimeException endFailure = new RuntimeException("end");
List<Throwable> reported = new ArrayList<>();
AtomicInteger fileExceptions = new AtomicInteger();
AtomicReference<Throwable> closeFailure = new AtomicReference<>();
CountDownLatch closed = new CountDownLatch(1);
ContextInternal context = ((VertxInternal) vertx).getOrCreateContext();
context.runOnContext(ignored -> {
AsyncFile file = vertx.fileSystem().openBlocking(testDir + pathSep + fileName, new OpenOptions());
context.exceptionHandler(reported::add);
file.exceptionHandler(ignored2 -> fileExceptions.incrementAndGet());
file.endHandler(ignored2 -> {
file.close().onComplete(ar -> {
closeFailure.set(ar.cause());
closed.countDown();
});
throw endFailure;
});
file.handler(buffer -> {
throw dataFailure;
});
});
TestUtils.awaitLatch(closed);
Assert.assertNull(closeFailure.get());
Assert.assertEquals(List.of(dataFailure, endFailure), reported);
Assert.assertEquals(0, fileExceptions.get());
}
}