[cache] Fix concurrent use of a cache entry (#3785)

Closes #3507
Fix some rare case where the concurrent readings of a cache entry can fail.

Signed-off-by: Gwendal Roulleau <gwendal.roulleau@gmail.com>
This commit is contained in:
Gwendal Roulleau 2023-08-30 14:23:35 +02:00 committed by GitHub
parent e765af06cb
commit 3ddbdb25ed
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -296,7 +296,7 @@ public class LRUMediaCacheEntry<V> {
}
}
// the cache file is now filled, get bytes from it.
long maxToRead = Math.min(currentSize, sizeToRead);
long maxToRead = Math.min(fileChannelLocal.size(), sizeToRead);
ByteBuffer byteBufferFromChannelFile = ByteBuffer.allocate((int) maxToRead);
int byteReadNumber = fileChannelLocal.read(byteBufferFromChannelFile, Integer.valueOf(start).longValue());
logger.trace("Read {} bytes from the filechannel", byteReadNumber);