Skip to content
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

feat: Add Breakpad support for Windows #278

Merged
merged 17 commits into from
Jun 17, 2020

Conversation

Mixaill
Copy link
Contributor

@Mixaill Mixaill commented Jun 5, 2020

Kinda working for me. Tested on example project.

Several questions:

  • Is it intended that breakpad backend sends data on second run?
  • Is it OK to create .envelope even when DSN is not set? In such case .dmp is not available until DSN will be set and envelope will be sended to the sentry.
  • Is there any utility to inspect/unpack .envelope ?

references #170
references #190

@Mixaill Mixaill force-pushed the breakpad-windows branch 6 times, most recently from 774c1d7 to d10734c Compare June 5, 2020 22:44
@jan-auer
Copy link
Member

jan-auer commented Jun 7, 2020

Thanks, @Mixaill. Answering your questions first:

  • Is it intended that breakpad backend sends data on second run?

This is intended, yes. Since breakpad runs everything in-process after the crash, there are only limited possibilities. Particularly, it is no longer possible to run reliable network communication, much less to upload an entire minidump. This is why we only write it to disk and upload it on the next run.

  • Is it OK to create .envelope even when DSN is not set? In such case .dmp is not available until DSN will be set and envelope will be sended to the sentry.

Excellent question. The current backend implementations (both Crashpad and Breakpad) do create the envelope and write it into the run folder. Ideally, however, you would not create the envelope. Not setting a DSN is intended to disable most of the SDK's functionality, and as such should also skip writing an envelope. This is also something for @Swatinem to chime in on.

Is there any utility to inspect/unpack .envelope ?

There is sentry__envelope_from_path, which loads an envelope. That only stores the raw payload, though, and you cannot inspect its contents. So far, we have not had the need to read an envelope once it's been serialized -- what would be your use case here?

external/CMakeLists.txt Outdated Show resolved Hide resolved
@Mixaill
Copy link
Contributor Author

Mixaill commented Jun 7, 2020

what would be your use case here

In my case I want to display something like that I had with CrashRpt before:
image
image

Sorry for Russian, but the common sense should be clear:

  • the first window with the general information and link to the Privacy Policy is displayed after crash
  • the second one with submission content is displayed on Inspect button click

So, I plan to implement it something like that:

  • Application crash
  • Breakpad UnhandledExceptionFilter execution
  • Start other process which waits for original application termination
  • After original application termination, initialize sentry in second application with the same DB folder
  • Display window like the first screenshot and display envelope content on inspect button
  • Send envelope on Send button and delete envelope on Close button.

@jan-auer
Copy link
Member

jan-auer commented Jun 7, 2020

That sounds excellent! In case you would like to show the files contained in the envelope, you can find a reference of its structure here.

If your background-uploader works well and you would like to share it, I would love to take a look at it. Uploading from a background process sounds like a useful addition to the SDK in general, even without a UI.

Copy link
Member

@Swatinem Swatinem left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks awesome already!

I think changing this condition here should be enough to run the relevant breakpad tests also on windows:

has_breakpad = sys.platform == "linux"

src/backends/sentry_backend_breakpad.cpp Outdated Show resolved Hide resolved
@Swatinem
Copy link
Member

Swatinem commented Jun 8, 2020

btw, the CI failure in Create Release Archive Job is our fault and we will try to fix this today.

@Mixaill
Copy link
Contributor Author

Mixaill commented Jun 8, 2020

I think changing this condition here should be enough to run the relevant breakpad tests also on windows:

Enabled

src/sentry_path.h Outdated Show resolved Hide resolved
src/backends/sentry_backend_breakpad.cpp Outdated Show resolved Hide resolved
src/sentry_path.h Outdated Show resolved Hide resolved
@Mixaill Mixaill force-pushed the breakpad-windows branch 2 times, most recently from 5353903 to 38289de Compare June 8, 2020 10:50
Copy link
Member

@Swatinem Swatinem left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you need to run make format to make python formatter happy ;-)

@Mixaill Mixaill force-pushed the breakpad-windows branch 2 times, most recently from 39d6ebb to 8d2c469 Compare June 8, 2020 13:03
@Mixaill
Copy link
Contributor Author

Mixaill commented Jun 8, 2020

Well, there are two problems

  • Assertion failed: !bgw->running && bgw->task_count == 0, file D:\a\1\s\src\sentry_sync.c, line 159 WinHTTP transport was destroyed before all tasks were executed?
  • CI hangs on assert instead of fail.

@Mixaill Mixaill force-pushed the breakpad-windows branch 2 times, most recently from b2d4d31 to 354378b Compare June 8, 2020 15:06
@Swatinem
Copy link
Member

Swatinem commented Jun 8, 2020

* WinHTTP transport was destroyed before all tasks were executed?

oh, its possible we are running into this:

// Ideally, it should default to 2s as per
// https://docs.sentry.io/error-reporting/configuration/?platform=rust#shutdown-timeout
// but we hit that timeout in our own integration tests, so rather
// increase it to 5s, as it was before.
if (!sentry__transport_shutdown(options->transport, 5000)) {
SENTRY_DEBUG("transport did not shut down cleanly");
}

I remember I was actually on windows when adding that comment.

That may be related to this:

/* TODO: this is dangerous and should be monotonic time */
uint64_t started = sentry__msec_time();
while (true) {
sentry__mutex_lock(&bgw->task_lock);
bool done = bgw->task_count == 0 && !bgw->running;
sentry__mutex_unlock(&bgw->task_lock);
if (done) {
sentry__thread_join(bgw->thread_id);
return 0;
}
sentry__mutex_lock(&bgw->done_signal_lock);
sentry__cond_wait_timeout(
&bgw->done_signal, &bgw->done_signal_lock, 250);
sentry__mutex_unlock(&bgw->done_signal_lock);
uint64_t now = sentry__msec_time();
if (now > started && now - started > timeout) {
return 1;
}

I remember we did observe time going backwards, I think that was actually on windows @jan-auer? Maybe @mitsuhiko can also chime in, since he wrote that original thread joining code.

I cant imagine why a HTTP request to localhost may take up more than 5s, so maybe our timer is jumping wildly.

@Swatinem
Copy link
Member

Swatinem commented Jun 8, 2020

so, what should we be doing in that case anyway? In the very least, we will leak memory from the background thread. Not quite sure if we should trigger a hard assert there?

@Mixaill
Copy link
Contributor Author

Mixaill commented Jun 8, 2020

I cant imagine why a HTTP request to localhost may take up more than 5s

Firewall configuration on test machine / VM?

@jan-auer jan-auer changed the title feat: add breakpad support for Windows feat: Add Breakpad support for Windows Jun 10, 2020
@eakoli
Copy link
Contributor

eakoli commented Jun 13, 2020

Ill have to look through this pr more closely as I didnt run into any of these issues. But I'm also based off of 0.3.1 not master.

also whenever I see a 00000000-0000-0000-0000-000000000000.envelope its due to a second crash while processing the current crash. Which was normally because of memory corruption etc.

@Mixaill
Copy link
Contributor Author

Mixaill commented Jun 13, 2020

00000000-0000-0000-0000-000000000000.envelope contains session information. It is also created on first run if you start sentry_example with start-session argument. It is full of zeroes in filename because session does not contains event ID.

@eakoli
Copy link
Contributor

eakoli commented Jun 13, 2020

@Swatinem It seems like it would be a good idea to add a way for internals to add an attachment via the event, so that the the Breakpad transport would no longer be needed.

@Swatinem
Copy link
Member

Indeed it would! We discussed this briefly to have a more fine-grained attachment support, but we didn’t reach a conclusion there yet. The native SDK is actually the first one which has attachment support AFAIK, and one of the few that works with envelopes internally.

@Mixaill
Copy link
Contributor Author

Mixaill commented Jun 17, 2020

@Swatinem rebased on top of master with merged monotonic time

@Swatinem Swatinem merged commit feee796 into getsentry:master Jun 17, 2020
@Swatinem
Copy link
Member

🎉 Amazing stuff, thanks for sticking with it this long ;-)

irov pushed a commit to irov/sentry-native that referenced this pull request Jun 17, 2020
sentry_path_t *dump_path = nullptr;
#ifdef SENTRY_PLATFORM_WINDOWS
dump_path = sentry__path_new(breakpad_dump_path);
dump_path = sentry__path_join_wstr(dump_path, minidump_id);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Mixaill @Swatinem I think this introduces a leak, as the join and append return a new path object.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch! I think you are right.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants