Browse Source

fix: don't crash Utility Processes on unhandled rejections (#45921)

* fix: don't crash on unhandled rejections

* Update docs/breaking-changes.md

Co-authored-by: Niklas Wenzel <[email protected]>

---------

Co-authored-by: Niklas Wenzel <[email protected]>
Shelley Vohr 1 month ago
parent
commit
c0e180758b
2 changed files with 16 additions and 0 deletions
  1. 13 0
      docs/breaking-changes.md
  2. 3 0
      shell/services/node/node_service.cc

+ 13 - 0
docs/breaking-changes.md

@@ -14,6 +14,19 @@ This document uses the following convention to categorize breaking changes:
 
 ## Planned Breaking API Changes (36.0)
 
+### Utility Process unhandled rejection behavior change
+
+Utility Processes will now warn with an error message when an unhandled
+rejection occurs instead of crashing the process.
+
+To restore the previous behavior, you can use:
+
+```js
+process.on('uncaughtException', () => {
+  process.exit(1)
+})
+```
+
 ### Removed:`isDefault` and `status` properties on `PrinterInfo`
 
 These properties have been removed from the PrinterInfo Object

+ 3 - 0
shell/services/node/node_service.cc

@@ -155,6 +155,9 @@ void NodeService::Initialize(
 
   node_env_->set_trace_sync_io(node_env_->options()->trace_sync_io);
 
+  // We do not want to crash the utility process on unhandled rejections.
+  node_env_->options()->unhandled_rejections = "warn-with-error-code";
+
   // Add Electron extended APIs.
   electron_bindings_->BindTo(node_env_->isolate(), node_env_->process_object());