Commit db713ae
Add error handling in InspectorPackagerConnection::connect()
Summary:
Fix a SIGSEGV crash that can occur during WebSocket connection in the React Native JS inspector when `JCxxInspectorPackagerConnectionDelegateImpl::connectWebSocket()` fails (for example, due to allocation failure when constructing the WebSocket delegate hybrid object, or a JNI exception thrown from the Java side).
Previously `InspectorPackagerConnection::Impl::connect()` had no error handling around the `connectWebSocket` call — any exception (`std::bad_alloc`, `JniException`, etc.) would propagate unhandled and terminate the process.
### Changes
1. **`InspectorPackagerConnection.cpp`**: Wrap `connectWebSocket` in try-catch. On failure, log the error, reset the WebSocket, and trigger `reconnect()` (existing 2-second retry mechanism). This is consistent with how other error paths in the same class already handle failures (e.g., `didFailWithError` and `didClose` both call `reconnect()`).
2. **`JCxxInspectorPackagerConnectionDelegateImpl.cpp`**: Add a null check on the JNI return value before calling `wrapInUniquePtr()` to prevent a null dereference if the Java method returns null.
Changelog:
[General][Fixed] - Handle exceptions thrown during WebSocket connect in `InspectorPackagerConnection` to avoid native crashes when the JS inspector fails to connect
[Android][Fixed] - Add null check on JNI return value in `JCxxInspectorPackagerConnectionDelegateImpl::connectWebSocket` to prevent null dereference
Differential Revision: D1009562671 parent 7ae9b66 commit db713ae
2 files changed
Lines changed: 7 additions & 1 deletion
File tree
- packages/react-native
- ReactAndroid/src/main/jni/react/devsupport
- ReactCommon/jsinspector-modern
Lines changed: 3 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
30 | 30 | | |
31 | 31 | | |
32 | 32 | | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
33 | 36 | | |
34 | 37 | | |
35 | 38 | | |
| |||
Lines changed: 4 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
341 | 341 | | |
342 | 342 | | |
343 | 343 | | |
344 | | - | |
| 344 | + | |
345 | 345 | | |
346 | 346 | | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
347 | 350 | | |
348 | 351 | | |
349 | 352 | | |
| |||
0 commit comments