diff --git a/activemq-core/src/main/java/org/apache/activemq/kaha/impl/async/DataFile.java b/activemq-core/src/main/java/org/apache/activemq/kaha/impl/async/DataFile.java index af5b122909..24e7a92a1b 100644 --- a/activemq-core/src/main/java/org/apache/activemq/kaha/impl/async/DataFile.java +++ b/activemq-core/src/main/java/org/apache/activemq/kaha/impl/async/DataFile.java @@ -88,10 +88,19 @@ public class DataFile extends LinkedNode implements Comparable { public synchronized RandomAccessFile openRandomAccessFile(boolean appender) throws IOException { RandomAccessFile rc = new RandomAccessFile(file, "rw"); // When we start to write files size them up so that the OS has a chance - // to allocate the file contigously. + // to allocate the file contiguously. if (appender) { if (length < preferedSize) { - rc.setLength(preferedSize); + try { + // this can throw if we run out of disk space + rc.setLength(preferedSize); + } catch (IOException ioe) { + try { + rc.close(); + } catch(Exception ignored) { + } + throw ioe; + } } } return rc;