Skip to content

handle oom error as IOException #6395

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ public void writeUserData(String sessionId, String userId) {
writer.flush();
} catch (Exception e) {
Logger.getLogger().w("Error serializing user metadata.", e);
} catch (OutOfMemoryError e) {
Logger.getLogger().w("OOM serializing user metadata.", e);
} finally {
CommonUtils.closeOrLog(writer, "Failed to close user metadata file.");
}
Expand All @@ -86,6 +88,9 @@ public String readUserId(String sessionId) {
} catch (Exception e) {
Logger.getLogger().w("Error deserializing user metadata.", e);
safeDeleteCorruptFile(f);
} catch (OutOfMemoryError e) {
Logger.getLogger().w("OOM deserializing user metadata.", e);
safeDeleteCorruptFile(f);
} finally {
CommonUtils.closeOrLog(is, "Failed to close user metadata file.");
}
Expand All @@ -108,6 +113,9 @@ public void writeKeyData(String sessionId, Map<String, String> keyData, boolean
} catch (Exception e) {
Logger.getLogger().w("Error serializing key/value metadata.", e);
safeDeleteCorruptFile(f);
} catch (OutOfMemoryError e) {
Logger.getLogger().w("OOM serializing key/value metadata.", e);
safeDeleteCorruptFile(f);
} finally {
CommonUtils.closeOrLog(writer, "Failed to close key/value metadata file.");
}
Expand All @@ -132,6 +140,9 @@ Map<String, String> readKeyData(String sessionId, boolean isInternal) {
} catch (Exception e) {
Logger.getLogger().w("Error deserializing user metadata.", e);
safeDeleteCorruptFile(f);
} catch (OutOfMemoryError e) {
Logger.getLogger().w("OOM deserializing user metadata.", e);
safeDeleteCorruptFile(f);
} finally {
CommonUtils.closeOrLog(is, "Failed to close user metadata file.");
}
Expand All @@ -155,6 +166,9 @@ public List<RolloutAssignment> readRolloutsState(String sessionId) {
} catch (Exception e) {
Logger.getLogger().w("Error deserializing rollouts state.", e);
safeDeleteCorruptFile(f);
} catch (OutOfMemoryError e) {
Logger.getLogger().w("OOM deserializing rollouts state.", e);
safeDeleteCorruptFile(f);
} finally {
CommonUtils.closeOrLog(is, "Failed to close rollouts state file.");
}
Expand All @@ -177,6 +191,9 @@ public void writeRolloutState(String sessionId, List<RolloutAssignment> rollouts
} catch (Exception e) {
Logger.getLogger().w("Error serializing rollouts state.", e);
safeDeleteCorruptFile(f);
} catch (OutOfMemoryError e) {
Logger.getLogger().w("OOM serializing rollouts state.", e);
safeDeleteCorruptFile(f);
} finally {
CommonUtils.closeOrLog(writer, "Failed to close rollouts state file.");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,8 @@ private void doWriteToLog(long timestamp, String msg) {
}
} catch (IOException e) {
Logger.getLogger().e("There was a problem writing to the Crashlytics log.", e);
} catch (OutOfMemoryError e) {
Logger.getLogger().e("OOM when writing to the Crashlytics log.", e);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,9 @@ private static int oldestEventFileFirst(@NonNull File f1, @NonNull File f2) {
private static void writeTextFile(File file, String text) throws IOException {
try (OutputStreamWriter writer = new OutputStreamWriter(new FileOutputStream(file), UTF_8)) {
writer.write(text);
} catch (OutOfMemoryError e) {
Logger.getLogger().w("Write text file out of memory.", e);
throw new IOException("out of memory");
}
}

Expand All @@ -421,6 +424,9 @@ private static void writeTextFile(File file, String text, long lastModifiedTimes
try (OutputStreamWriter writer = new OutputStreamWriter(new FileOutputStream(file), UTF_8)) {
writer.write(text);
file.setLastModified(convertTimestampFromSecondsToMs(lastModifiedTimestampSeconds));
} catch (OutOfMemoryError e) {
Logger.getLogger().w("Write text file out of memory.", e);
throw new IOException("out of memory");
}
}

Expand All @@ -434,6 +440,9 @@ private static String readTextFile(@NonNull File file) throws IOException {
bos.write(readBuffer, 0, read);
}
return new String(bos.toByteArray(), UTF_8);
} catch (OutOfMemoryError e) {
Logger.getLogger().w("Read text file out of memory.", e);
throw new IOException("out of memory");
}
}

Expand Down
Loading