Skip to content

Commit

Permalink
Improve message cache behavior in case of io error
Browse files Browse the repository at this point in the history
  • Loading branch information
AsamK committed Sep 23, 2023
1 parent 0bdc400 commit 6774725
Showing 1 changed file with 11 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,21 @@ public Iterable<CachedMessage> getCachedMessages() {
public CachedMessage cacheMessage(SignalServiceEnvelope envelope, RecipientId recipientId) {
final var now = System.currentTimeMillis();

File cacheFile;
try {
cacheFile = getMessageCacheFile(recipientId, now, envelope.getTimestamp());
} catch (IOException e) {
logger.warn("Failed to create recipient folder in disk cache: {}", e.getMessage());
throw new RuntimeException(e);
}

final var cachedMessage = new CachedMessage(cacheFile, envelope);
try {
var cacheFile = getMessageCacheFile(recipientId, now, envelope.getTimestamp());
MessageCacheUtils.storeEnvelope(envelope, cacheFile);
return new CachedMessage(cacheFile, envelope);
return cachedMessage;
} catch (IOException e) {
logger.warn("Failed to store encrypted message in disk cache, ignoring: {}", e.getMessage());
return null;
return cachedMessage;
}
}

Expand Down

0 comments on commit 6774725

Please sign in to comment.