Skip to content

Commit b58e50b

Browse files
committed
Fix race condition in PageManagerFlushThread during database shutdown
1 parent 432707d commit b58e50b

2 files changed

Lines changed: 9 additions & 0 deletions

File tree

engine/src/main/java/com/arcadedb/engine/PageManagerFlushThread.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,9 @@ else if (!pagesToFlush.pages.isEmpty()) {
153153
// SET THE PAGES TO FLUSH TO BE RETRIEVED BY A CONCURRENT DB CLOSE = FORCE FLUSH OF PAGES
154154
nextPagesToFlush.set(pagesToFlush);
155155
try {
156+
if (!pagesToFlush.database.isOpen())
157+
return;
158+
156159
synchronized (pagesToFlush.pages) {
157160
for (final MutablePage page : pagesToFlush.pages) {
158161
try {

engine/src/main/java/com/arcadedb/engine/PaginatedComponentFile.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,9 @@ public int write(final MutablePage page) throws IOException {
147147
// NO NEED TO SYNCHRONIZE THE BUFFER BECAUSE MUTABLE PAGES ARE NOT SHARED
148148
buffer.rewind();
149149
try {
150+
if (channel == null)
151+
throw new ClosedChannelException();
152+
150153
channel.write(buffer, (page.getPhysicalSize() * (long) pageNumber));
151154
} catch (final ClosedChannelException e) {
152155
LogManager.instance().log(this, Level.SEVERE, "File '%s' was closed on write. Reopen it and retry...", null, fileName);
@@ -189,6 +192,9 @@ public void read(final CachedPage page) throws IOException {
189192
final ByteBuffer buffer = page.getByteBuffer();
190193

191194
try {
195+
if (channel == null)
196+
throw new ClosedChannelException();
197+
192198
channel.read(buffer, page.getPhysicalSize() * (long) page.getPageId().getPageNumber());
193199
} catch (final ClosedChannelException e) {
194200
LogManager.instance().log(this, Level.SEVERE, "File '%s' was closed on read. Reopen it and retry...", null, fileName);

0 commit comments

Comments
 (0)