fix(windows): fix crash in getIpAddressSync #631
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Overview
Even if not properly documented, some properties of
windows.networking.connectivity.connectionprofile
can throw. It's the case ofNetworkAdapter
since it's then callingcheck_hresult
which will throw if the returned hresult is an error one.Since
RNCNetInfo::getIpAddressSync
is marked asnoexcept
, any exception thrown in this method will callstd::terminate
.This commit is to return
"unknown"
in this case.Test Plan
Unfortunately, I wasn't able to reproduce the crash some of our users face myself so I can't validate it fixes it.
Though I imported these changes in our own RN Windows project and made sure IP info is still working in the general case!
For reference, here is the stack trace we get in our crash reporting system:
RNCNetInfoCPP!__GSHandlerCheck_EH4+0x64 [D:\a_work\1\s\src\vctools\crt\vcstartup\src\gs\amd64\gshandlereh4.cpp @ 86]
RNCNetInfoCPP!winrt::throw_hresult+0x200 [node_modules@react-native-community\netinfo\windows\RNCNetInfoCPP\Generated Files\winrt\base.h @ 4688]
RNCNetInfoCPP!winrt::check_hresult+0x448 [node_modules@react-native-community\netinfo\windows\RNCNetInfoCPP\RNCNetInfo.cpp @ 111] [inlined in RNCNetInfoCPP!winrt::ReactNativeNetInfo::implementation::getIpAddressSync+0x4a0 [node_modules@react-native-community\netinfo\windows\RNCNetInfoCPP\RNCNetInfo.cpp @ 111]]
RNCNetInfoCPP!winrt::ReactNativeNetInfo::implementation::RNCNetInfo::GetNetworkStatus$_ResumeCoro$1+0x75c [node_modules@react-native-community\netinfo\windows\RNCNetInfoCPP\RNCNetInfo.cpp @ 191]
RNCNetInfoCPP!winrt::ReactNativeNetInfo::implementation::RNCNetInfo::GetNetworkStatus$_InitCoro$2+0x194 [node_modules@react-native-community\netinfo\windows\RNCNetInfoCPP\RNCNetInfo.cpp @ 15732480]
RNCNetInfoCPP!winrt::ReactNativeNetInfo::implementation::RNCNetInfo::GetNetworkStatus+0x44 [node_modules@react-native-community\netinfo\windows\RNCNetInfoCPP\RNCNetInfo.cpp @ 15732480]
RNCNetInfoCPP!<lambda_07af3bc3acbb5d7aa0533ab2f666cdc6>::operator()+0x78 [node_modules@react-native-community\netinfo\windows\RNCNetInfoCPP\RNCNetInfo.cpp @ 147]
RNCNetInfoCPP!winrt::impl::delegate<winrt::Windows::Networking::Connectivity::NetworkStatusChangedEventHandler,<lambda_07af3bc3acbb5d7aa0533ab2f666cdc6> >::Invoke+0xc [node_modules@react-native-community\netinfo\windows\RNCNetInfoCPP\Generated Files\winrt\Windows.Networking.Connectivity.h @ 791]