-
Notifications
You must be signed in to change notification settings - Fork 207
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
Capture trace of error reporting thread and identify with boolean flag #355
Conversation
…olean flag in serialised json
1 similar comment
private final Thread[] threads; | ||
private final Map<Thread, StackTraceElement[]> stackTraces; | ||
private final long currentThreadId; |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tested this with a few cases:
- Spinning up background threads which periodically do work and then cause a handled or unhandled exception
- Causing handled or unhandled exceptions from UI events
- Causing handled or unhandled exceptions from the main thread immediately
In the case of unhandled exceptions, an incorrect thread is generally marked as the unhandledException
thread is not the same as the error reporting thread. So a thread is marked but it has a different stacktrace from the Stacktrace tab.
For handled exceptions, I never see any thread marked as the reporting thread on the Threads tab.
private final Thread[] threads; | ||
private final Map<Thread, StackTraceElement[]> stackTraces; | ||
private final long currentThreadId; |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
*/ | ||
private Thread[] sanitiseThreads(long currentThreadId, | ||
Map<Thread, StackTraceElement[]> liveThreads) { | ||
private Thread[] sanitiseThreads(Map<Thread, StackTraceElement[]> liveThreads) { |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
Thanks for the review @kattrali - I've updated
I was not able to reproduce this behaviour, did you have a code example that will trigger this? |
I've updated the thread serialisation to capture the threads at the point of report generation, rather than serialisation. I've also made sure that we pass in the current |
Nothing special, just fired up the example app with the handled exception buttons. It still happens sometimes. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tested this further, made some suggestions for how to get a consistent result for both handled and unhandled exceptions. The error reporting thread for handled errors looks as I would expect (though sometimes no thread is marked?), though unhandled errors may end up with an unexpected stack if they are from a pool and should be set to the exception stack.
@@ -77,12 +77,12 @@ public void uncaughtException(@NonNull Thread thread, @NonNull Throwable throwab | |||
StrictMode.setThreadPolicy(StrictMode.ThreadPolicy.LAX); | |||
|
|||
client.cacheAndNotify(throwable, Severity.ERROR, | |||
metaData, severityReason, violationDesc); | |||
metaData, severityReason, violationDesc, thread); |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
I've tried pressing each button in the example app 10x on an API 27 emulator. For all of the 70 received events "Error reported from this thread" is present on one entry in the threads tab. Do I need to increase the frequency to reproduce this issue, or is there some sort of code change required? One potential cause I can think of would be that If this is the case then we might be able to record the thread ID, name, and a zero-element array stacktrace by adding the terminated thread into the set of live threads. However, I'm still not sure how this could explain why this behaviour was observed for a blocking
I discussed this with Duncan at project kick-off and believe the requested behaviour was to capture the thread trace for both handled/unhandled errors, rather than the exception stacktrace. I'll run this past the necessary Slack channel before making the change |
This behaviour is reproducible on API 25 not API 27, investigating further |
… already a key An issue exists in api 24/25 where not all threads are reported correctly from Thread.getAllStacktraces(). Adding it in manually and calling Thread.getStacktrace() appears to negate this behaviour. https://issuetracker.google.com/issues/64122757
…or, rather than thread trace, f
…ace for unhandled errors
|
||
private fun verifyCurrentThreadStructure(json: JSONArray, | ||
currentThreadId: Long, | ||
action: ((thread: JSONObject) -> Unit)? = null) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Allows passing a function that will be invoked when the errorReportingThread json is found. This means assertions can be run with less boilerplate finding the necessary thread
@NonNull Thread thread, | ||
boolean unhandled) { | ||
Throwable exc = unhandled ? exception : null; | ||
this.threadState = new ThreadState(config, thread, Thread.getAllStackTraces(), exc); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If an exception is passed in (default for unhandled errors), the exception stacktrace will be serialised rather than the thread stacktrace
There appears to be a bug in API levels 24/25 where I have applied a workaround for this by capturing the stacktrace of the I have also altered the thread serialisation so that the exception stacktrace is used for the errorReportingThread, for unhandled errors only. Testing included:
|
Add mazerunner scenario for thread id
Added an additional mazerunner scenario, which has passed locally (CI build is blocked again but I believe this should be ready for review.) |
Feature: Error Reporting Thread | ||
|
||
Scenario: Only 1 thread is flagged as the error reporting thread | ||
When I run "HandledExceptionScenario" with the defaults |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it worth adding a scenario for unhandled as well?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, good point.
The current thread stacktrace for handled events looks like this:
Should we trim off everything from |
@simonbowring this is the requested behaviour for handled events - unhandled events will show the exception stacktrace rather than the thread trace. |
adds a scenario for an unhandled exception, that ensures the error reporting thread is serialised. For handled exceptions, the thread trace should be reported. For unhandled exceptions, the exception stacktrace should be used instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Add react native maven repo earlier in plugin lifecycle
Bump bugsnag-android to v5.11.0
Goal
Captures the trace of
Thread.currentThread()
, which was previously omitted, and to identify it with a boolean flag in the serialised JSON.Changeset
ThreadState
to stop removing the current thread from serialisationerrorReportingThread
boolean flag by checking thread IDTests
Added unit tests for general ThreadState serialisation, and for checking that the current thread is now captured. Ran mazerunner locally, tested with dashboard.
Review
For the submitter, initial self-review:
For the pull request reviewer(s), this changeset has been reviewed for: