mirror of
https://github.com/jlengrand/vert.x.git
synced 2026-03-10 08:51:19 +00:00
Do not lock the handler calls in AsyncFile - see #3140
This commit is contained in:
@@ -400,22 +400,30 @@ public class AsyncFileImpl implements AsyncFile {
|
||||
});
|
||||
}
|
||||
|
||||
private synchronized void handleBuffer(Buffer buff) {
|
||||
|
||||
private void handleBuffer(Buffer buff) {
|
||||
Handler<Buffer> handler;
|
||||
synchronized (this) {
|
||||
handler = this.handler;
|
||||
}
|
||||
if (handler != null) {
|
||||
checkContext();
|
||||
handler.handle(buff);
|
||||
}
|
||||
}
|
||||
|
||||
private synchronized void handleEnd() {
|
||||
handler = null;
|
||||
private void handleEnd() {
|
||||
Handler<Void> endHandler;
|
||||
synchronized (this) {
|
||||
handler = null;
|
||||
endHandler = this.endHandler;
|
||||
}
|
||||
if (endHandler != null) {
|
||||
checkContext();
|
||||
endHandler.handle(null);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private synchronized void doFlush(Handler<AsyncResult<Void>> handler) {
|
||||
checkClosed();
|
||||
context.executeBlockingInternal((Promise<Void> fut) -> {
|
||||
|
||||
@@ -1564,6 +1564,25 @@ public class FileSystemTest extends VertxTestBase {
|
||||
await();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testReadStreamNoLock() throws Exception {
|
||||
String fileName = "some-file.dat";
|
||||
int chunkSize = 16384;
|
||||
int chunks = 1;
|
||||
byte[] content = TestUtils.randomByteArray(chunkSize * chunks);
|
||||
createFile(fileName, content);
|
||||
vertx.fileSystem().open(testDir + pathSep + fileName, new OpenOptions(), onSuccess(rs -> {
|
||||
rs.handler(buff -> {
|
||||
assertFalse(Thread.holdsLock(rs));
|
||||
});
|
||||
rs.endHandler(v -> {
|
||||
assertFalse(Thread.holdsLock(rs));
|
||||
testComplete();
|
||||
});
|
||||
}));
|
||||
await();
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
public void testPumpFileStreams() throws Exception {
|
||||
|
||||
Reference in New Issue
Block a user