Skip to content

Commit

Permalink
Add an Evnrionmently Opt-in crash handler
Browse files Browse the repository at this point in the history
  • Loading branch information
waahm7 committed Jun 29, 2023
1 parent 4625964 commit 21ee8b9
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,7 @@ Please note that on Mac, once a private key is used with a certificate, that cer
```
static: certificate has an existing certificate-key pair that was previously imported into the Keychain. Using key from Keychain instead of the one provided.
```

## Custom Configurations
- Crash Handler: You can enable the crash handler by setting the environment variable `AWS_CRT_ENABLE_CRASH_HANDLER=1`.
This instructs the AWS Common Runtime (CRT) to take over the process's signal handlers to generate crash dumps in the event of a fatal error.
8 changes: 7 additions & 1 deletion source/module.c
Original file line number Diff line number Diff line change
Expand Up @@ -804,6 +804,7 @@ static PyMethodDef s_module_methods[] = {

static const char s_module_name[] = "_awscrt";
PyDoc_STRVAR(s_module_doc, "C extension for binding AWS implementations of MQTT, HTTP, and friends");
AWS_STATIC_STRING_FROM_LITERAL(s_crash_handler_env_var, "AWS_CRT_ENABLE_CRASH_HANDLER");

/*******************************************************************************
* Module Init
Expand All @@ -828,11 +829,16 @@ PyMODINIT_FUNC PyInit__awscrt(void) {
}

s_init_allocator();
s_install_crash_handler();

/* Don't report this memory when dumping possible leaks. */
struct aws_allocator *nontracing_allocator = aws_default_allocator();

struct aws_string *crash_handler_env = NULL;
aws_get_environment_value(nontracing_allocator, s_crash_handler_env_var, &crash_handler_env);
if (aws_string_eq_c_str(crash_handler_env, "1")) {
s_install_crash_handler();
}

aws_http_library_init(nontracing_allocator);
aws_auth_library_init(nontracing_allocator);
aws_mqtt_library_init(nontracing_allocator);
Expand Down

0 comments on commit 21ee8b9

Please sign in to comment.