You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Basically that AuditFileWriter implementation opens new files on every attempt and never closes them. After some time the server crashes because of "too many open files".
I have to say this is a quite bewildering and severe bug for an audit library, whose purpose is, after all, to write to a file.
To me this method is clearly the culprit:
@Override
public ZeroCopyFileWriter write(String event) {
// String realPath = FileHandlerUtil.generateOutputFilePath(path);
String realPath = FileHandlerUtil.generateOutputFilePath(
path,
FileHandlerUtil.generateAuditFileName());
try {
if (FileHandlerUtil.isFileAlreadyExists(realPath)) {
randomAccessFile = new RandomAccessFile(realPath, CoreConstants.READ_WRITE);
} else {
randomAccessFile = new RandomAccessFile(new File(realPath), CoreConstants.READ_WRITE);
}
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
fileChannel = randomAccessFile.getChannel();
String str2 = event + CoreConstants.NEW_LINE;
long numBytes = str2.getBytes().length;
InputStream inputStream = new ByteArrayInputStream(str2.getBytes(Charset.forName("UTF-8")));
try {
// move the cursor to the end of the file
randomAccessFile.seek(randomAccessFile.length());
// obtain the a file channel from the RandomAccessFile
try (ReadableByteChannel inputChannel = Channels.newChannel(inputStream);) {
fileChannel.transferFrom(inputChannel, randomAccessFile.length(), numBytes);
} catch (IOException e) {
e.printStackTrace();
}
} catch (IOException e) {
e.printStackTrace();
}
return this;
}
The text was updated successfully, but these errors were encountered:
Basically that AuditFileWriter implementation opens new files on every attempt and never closes them. After some time the server crashes because of "too many open files".
I have to say this is a quite bewildering and severe bug for an audit library, whose purpose is, after all, to write to a file.
To me this method is clearly the culprit:
The text was updated successfully, but these errors were encountered: