Skip to content

Commit e953d29

Browse files
committed
Revert "ref(android): Persist the session snapshot outside the scope lock"
This reverts commit da288f8.
1 parent da288f8 commit e953d29

1 file changed

Lines changed: 16 additions & 35 deletions

File tree

‎sentry-android-core/src/main/java/io/sentry/android/core/InternalSentrySdk.java‎

Lines changed: 16 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@
4141
import java.util.List;
4242
import java.util.Locale;
4343
import java.util.Map;
44-
import java.util.concurrent.atomic.AtomicBoolean;
4544
import java.util.concurrent.atomic.AtomicReference;
4645
import org.jetbrains.annotations.ApiStatus;
4746
import org.jetbrains.annotations.NotNull;
@@ -250,51 +249,33 @@ public static SentryId captureEnvelopeNonTerminating(final @NotNull byte[] envel
250249
final @NotNull EnvelopeEventState eventState = eventStateOf(envelope, serializer);
251250

252251
if (eventState != EnvelopeEventState.NONE) {
253-
final @Nullable Session session = recordSessionError(scopes, options, eventState);
254-
if (session != null && options.getEnvelopeDiskCache() instanceof EnvelopeCache) {
255-
((EnvelopeCache) options.getEnvelopeDiskCache()).persistCurrentSession(session);
256-
}
257-
}
258-
259-
return scopes.captureEnvelope(envelope);
260-
} catch (Exception e) {
261-
options.getLogger().log(SentryLevel.ERROR, "Failed to capture envelope", e);
262-
}
263-
return null;
264-
}
265-
266-
/**
267-
* Records the envelope's error on the current session under the scope lock and returns the
268-
* snapshot taken while holding it, so the caller can persist it without keeping the lock during
269-
* disk I/O. Returns null when there is no session or it had already reached a terminal state.
270-
*/
271-
private static @Nullable Session recordSessionError(
272-
final @NotNull IScopes scopes,
273-
final @NotNull SentryOptions options,
274-
final @NotNull EnvelopeEventState eventState) {
275-
final @NotNull AtomicReference<Session> snapshotRef = new AtomicReference<>();
276-
scopes.configureScope(
277-
scope -> {
278-
final @NotNull AtomicBoolean updated = new AtomicBoolean(false);
279-
final @Nullable Session snapshot =
252+
scopes.configureScope(
253+
scope -> {
280254
scope.withSession(
281255
session -> {
282256
if (session != null) {
283-
updated.set(
257+
final boolean updated =
284258
eventState == EnvelopeEventState.UNHANDLED
285259
? session.recordNonTerminatingUnhandledError()
286-
: session.update(null, null, true, null));
260+
: session.update(null, null, true, null);
261+
if (updated && options.getEnvelopeDiskCache() instanceof EnvelopeCache) {
262+
((EnvelopeCache) options.getEnvelopeDiskCache())
263+
.persistCurrentSession(session);
264+
}
287265
} else {
288266
options
289267
.getLogger()
290268
.log(INFO, "Session is null on captureEnvelopeNonTerminating");
291269
}
292270
});
293-
if (updated.get()) {
294-
snapshotRef.set(snapshot);
295-
}
296-
});
297-
return snapshotRef.get();
271+
});
272+
}
273+
274+
return scopes.captureEnvelope(envelope);
275+
} catch (Exception e) {
276+
options.getLogger().log(SentryLevel.ERROR, "Failed to capture envelope", e);
277+
}
278+
return null;
298279
}
299280

300281
/** What the events inside an envelope amount to, from the session's point of view. */

0 commit comments

Comments
 (0)