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

fix(windows): fix crash in getIpAddressSync #631

Merged

Conversation

aironefr
Copy link
Contributor

@aironefr aironefr commented Oct 14, 2022

Overview

Even if not properly documented, some properties of windows.networking.connectivity.connectionprofile can throw. It's the case of NetworkAdapter since it's then calling check_hresult which will throw if the returned hresult is an error one.

Since RNCNetInfo::getIpAddressSync is marked as noexcept, any exception thrown in this method will call std::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]

Even if not properly documented, some properties of
`windows.networking.connectivity.connectionprofile` can throw.
It's the case of `NetworkAdapter` since it's then calling
`check_hresult` which will throw if the returned hresult is an error one.

Since `RNCNetInfo::getIpAddressSync` is marked as `noexcept`, any exception
thrown in this method will call `std::terminate`.

This commit is to return `"unknown"` in this case.
Copy link
Contributor

@mikehardy mikehardy left a comment

Choose a reason for hiding this comment

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

I don't speak Windows C++ well at all but I do know enough to know that std::terminate is not what anyone wants 😆 - thanks for raising this, much appreciated

@mikehardy mikehardy added the pending merge A PR that will be merged shortly, waiting for CI or final comment label Oct 14, 2022
@mikehardy mikehardy merged commit cc3ed0f into react-native-netinfo:master Oct 15, 2022
@mikehardy mikehardy removed the pending merge A PR that will be merged shortly, waiting for CI or final comment label Oct 15, 2022
github-actions bot pushed a commit that referenced this pull request Oct 15, 2022
## [9.3.5](v9.3.4...v9.3.5) (2022-10-15)

### Bug Fixes

* **windows:** fix crash in getIpAddressSync ([#631](#631)) ([cc3ed0f](cc3ed0f))
@matt-oakes
Copy link
Collaborator

🎉 This PR is included in version 9.3.5 🎉

The release is available on:

Your semantic-release bot 📦🚀

@aironefr aironefr deleted the fix-getIpAddressSyncCrash branch October 17, 2022 07:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants