Repository navigation
Conversation
PR risk: mediumFor commit Main concerns: public contract, host performance, data sent to Sentry. Rules that block low also fired:
This label is a hint for reviewers, not an approval. |
|
📲 Install BuildsAndroid
|
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Want higher recall? High effort reviews run extra passes and find more bugs. A team admin can switch effort levels in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit c7b7e2c. Configure here.
runningcode
left a comment
There was a problem hiding this comment.
starting to go through this, just leaving some early comments and I'll get back to reviewing tomorrow!
| } | ||
|
|
||
| @SuppressWarnings("ReferenceEquality") | ||
| private void postOnManagerThread(final @NotNull Runnable task) { |
There was a problem hiding this comment.
when I see these types of methods, i always wonder if it could cause out of order execution and if that matters.
In this case, my clanker tells me that it only ever goes down the first branch so to simplify the code we could remove this method entirely.
| // Runs before any other task of this single-thread executor. | ||
| current.execute(() -> executorThread = Thread.currentThread()); | ||
| } | ||
| current.execute(() -> { |
There was a problem hiding this comment.
should we wrap the execution of the task in a try/catch ?
otherwise my clanker tells me that the ScheduledThreadPoolExecutor swallows the exception and there's no way of knowing the task failed and could leave us in a bad state.
| private final @NotNull MonotonicTicker ticker; | ||
| private final @NotNull EpochClock epochClock; | ||
| private final long pollingIntervalMs; | ||
| private final long maxRecordingTimeMs; |
There was a problem hiding this comment.
my clanker tells me that these maxRecordingTimeMs and maxSamples are essentially the same limit since we're sampling the app at a fixed rate.
it could be confusing to users which one to adjust when their samples stop if they aren't aware there are two different limits. could we consolidate?
There was a problem hiding this comment.
The manager-thread model is clean and the tests are thorough. Two things I'd like settled before this lands, plus a +1 on the open thread about task exceptions:
HangManagerignores which signal opened the hang.signalListenerthrows away thesignalargument, so inhandleSignalChangedanIDLEfrom any signal ends the open hang, and inhandleSignalCanceleda cancel from any signal drops it. With two signals, signal B goingIDLEor canceling while signal A is stillSUSPICIOUStruncates or discards A's hang. A won't re-reportSUSPICIOUSbecause it only reports changes, so the rest of that hang is lost. The testsecond suspicious from another signal does not start a second recordlocks in this behavior: A'sIDLEends the record while the other signal is still suspicious. Either track the signal that opened the hang and end or cancel only on its events, or take a singleHangSignalif more than one isn't a real use case. Right now theList<HangSignal>API promises more than the state machine supports.HangRecorder.startclears the stores at the start of every persisting hang. On the next launch, main-thread hangs during startup are common. If one starts before the fatal ANR path has read the previous process's samples, those samples are wiped. Can you point to where the ordering is guaranteed (read before the firstsubscribe, or a store per process run)? If it lives in a later PR in the stack, a short note in theHangManagerJavadoc would help.
The failing Build Job ubuntu-latest is DistrustedCertificatesTest in :sentry, which this PR doesn't touch.
| listener.onMetronomeTick(nowMs); | ||
| } | ||
| final @Nullable HangRecorder recorder = activeRecorder; | ||
| if (recorder != null && nowMs - recorder.getStartTimeMs() < maxRecordingTimeMs) { |
There was a problem hiding this comment.
this is effectively the same thing as Deadline. Can we use that abstraction here instead of manually doing math?
runningcode
left a comment
There was a problem hiding this comment.
Sorry for the junior post there, i was asking it about this PR and it decided to post its review here.
My clanker proposed this alternative design in order to remove the Metronome and simplify the code. That would fix:
thisescapeMetronomeinterfaces removed- my comment about the
postOnManagerThread - all the listener wiring
the proposed design that my clanker came up with is that the manager asks on every tick and the signal just answers.
what do you think of that approach? it says the trade off is that it assumes the signals are polled on a tick which might not be the case for future use cases of this but I always say YAGNI.
My clanker gave me some code samples for this approach that I can share. Happy to have a call to discuss it!
| } | ||
|
|
||
| /** | ||
| * The last unsubscribe closes the manager: it stops the signals and the tick, drops an open hang |
There was a problem hiding this comment.
This is somewhat unexpected here since usually the principle is "whatever creates it, closes it" so that the lifecycle is clear.
| this.maxRecordingTimeMs = maxRecordingTimeMs; | ||
| this.maxSamples = maxSamples; | ||
| this.executorFactory = executorFactory; | ||
| this.signals = Collections.unmodifiableList(new ArrayList<>(signalFactory.create(this))); |
There was a problem hiding this comment.
this is a general design pattern thing: its not a good idea to pass (this) in the constructor because then another object may see this object before it is crated which breaks the guarantees that final gives us.

Foundation for Non-Fatal ANRs:
HangManagerand the central loop, including all required interfacesHangRecordersamples the collectors on the manager's 66 ms tick thread, and the manager gives theHangRecordto the subscribers that asked for it.Design
See full spec for more details: Non-Fatal ANR Architecture (JAVA-777)
Example Event: https://sentry-sdks.sentry.io/issues/7865095622/events/6d88b353646b4c2d884a2180f83190d0/
#skip-changelog