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

[iOS] Crash in RCTWebSocketModule didFailWithError #28278

Closed
Etienne-M opened this issue Mar 10, 2020 · 6 comments
Closed

[iOS] Crash in RCTWebSocketModule didFailWithError #28278

Etienne-M opened this issue Mar 10, 2020 · 6 comments
Labels
Needs: Attention Issues where the author has responded to feedback. Needs: Repro This issue could be improved with a clear list of steps to reproduce the issue. Stale There has been a lack of activity on this issue and it may be closed soon.

Comments

@Etienne-M
Copy link

Description:

We're seeing some crashes in our Crashlytics dashboard with the following error:

Fatal Exception: NSInvalidArgumentException
*** -[__NSPlaceholderDictionary initWithObjects:forKeys:count:]: attempt to insert nil object from objects[0]

coming from

RCTWebSocketModule.m
-[RCTWebSocketModule webSocket:didFailWithError:]

React Native version: 0.61.5

Steps To Reproduce

Unknown, although having a WebSocket would be a good start to reproduce.

Expected Results

The app should not crash.

@xiao99xiao
Copy link

xiao99xiao commented Mar 11, 2020

This issue exists for a long time. The reason is the socketID and error in RCTWebSocketModule.m could sometimes be nil .
We patched the file like below and it never bothered us again.

-    @"message": error.localizedDescription,
-    @"id": socketID
+    @"message": error.localizedDescription ?: @"",
+    @"id": socketID ?: @(-1)

@chrisglein chrisglein added Needs: Environment Info Please run `react-native info` and edit your issue with that command's output. Needs: Author Feedback labels Mar 11, 2020
@chrisglein
Copy link

Can you produce a minimal repo so we can narrow this down? (e.g. a Snack or pointer to a repo of a minimal repo)
You provided the version (thank you!), but can you run 'react-native info' to get the rest of the context?

@react-native-bot react-native-bot removed the Needs: Environment Info Please run `react-native info` and edit your issue with that command's output. label Mar 11, 2020
@chrisglein chrisglein added Needs: Repro This issue could be improved with a clear list of steps to reproduce the issue. and removed Needs: Triage 🔍 labels Mar 18, 2020
@Etienne-M
Copy link
Author

Can you produce a minimal repo so we can narrow this down? (e.g. a Snack or pointer to a repo of a minimal repo)
You provided the version (thank you!), but can you run 'react-native info' to get the rest of the context?

Hello! Sorry, it took me a while to get you this info. There you:

System:
OS: macOS Mojave 10.14.6
CPU: (3) x64 Intel(R) Core(TM) i7-8700B CPU @ 3.20GHz
Memory: 10.96 GB / 16.00 GB
Shell: 3.2.57 - /bin/bash
Binaries:
Node: 12.13.0 - ~/.nvm/versions/node/v12.13.0/bin/node
npm: 6.14.3 - ~/.nvm/versions/node/v12.13.0/bin/npm
SDKs:
iOS SDK:
Platforms: iOS 13.2, DriverKit 19.0, macOS 10.15, tvOS 13.2, watchOS 6.1
IDEs:
Xcode: 11.3.1/11C505 - /usr/bin/xcodebuild
npmPackages:
@react-native-community/cli: 3.0.4 => 3.0.4
react: 16.9.0 => 16.9.0
react-native: 0.61.5 => 0.61.5

As for steps to reproduce, I can't really help you with that, I'm sorry

@github-actions github-actions bot added Needs: Attention Issues where the author has responded to feedback. and removed Needs: Author Feedback labels Mar 31, 2020
@stale
Copy link

stale bot commented Jul 3, 2020

Hey there, it looks like there has been no activity on this issue recently. Has the issue been fixed, or does it still require the community's attention? This issue may be closed if no further activity occurs. You may also label this issue as a "Discussion" or add it to the "Backlog" and I will leave it open. Thank you for your contributions.

@stale stale bot added the Stale There has been a lack of activity on this issue and it may be closed soon. label Jul 3, 2020
@stale
Copy link

stale bot commented Jul 11, 2020

Closing this issue after a prolonged period of inactivity. If this issue is still present in the latest release, please feel free to create a new issue with up-to-date information.

@luatnd
Copy link

luatnd commented Aug 19, 2020

This issue still occurs, some bugs in 3rd-party lib can lead to this issues, but it would be nice if react-native can show enough stack-trace to recognize which lib causing this issue

facebook-github-bot pushed a commit that referenced this issue Oct 12, 2020
Summary:
This PR attempts to fix issue #28278 and #29525

On Crashlytics, the following error occurs in file `RCTWebSocketModule.m` at method `-[RCTWebSocketModule webSocket:didFailWithError:]` when a nil value is inserted into a dictionary as a value.

```
Fatal Exception: NSInvalidArgumentException
*** -[__NSPlaceholderDictionary initWithObjects:forKeys:count:]: attempt to insert nil object from objects[0]
```

This PR is following the suggestion of this: #28278 (comment) and it replaces the values of any property if it is nil. In detail:
- it converts `error` to empty NSString if the original value is nil
- it converts `socketID` to a NSNumber object, which stores `-1` if the original value is nil

## Changelog

[iOS] [Fixed] - A crash in WebSocket module

Pull Request resolved: #30066

Test Plan: We were not able to reproduce the crash, but the report itself provided enough information to find a solution for this issue.

Reviewed By: shergin

Differential Revision: D24241147

Pulled By: sammy-SC

fbshipit-source-id: d5d632b49ca77b5d8be8b9c32358bef68f17d30a
kelset pushed a commit that referenced this issue Nov 27, 2020
Summary:
This PR attempts to fix issue #28278 and #29525

On Crashlytics, the following error occurs in file `RCTWebSocketModule.m` at method `-[RCTWebSocketModule webSocket:didFailWithError:]` when a nil value is inserted into a dictionary as a value.

```
Fatal Exception: NSInvalidArgumentException
*** -[__NSPlaceholderDictionary initWithObjects:forKeys:count:]: attempt to insert nil object from objects[0]
```

This PR is following the suggestion of this: #28278 (comment) and it replaces the values of any property if it is nil. In detail:
- it converts `error` to empty NSString if the original value is nil
- it converts `socketID` to a NSNumber object, which stores `-1` if the original value is nil

## Changelog

[iOS] [Fixed] - A crash in WebSocket module

Pull Request resolved: #30066

Test Plan: We were not able to reproduce the crash, but the report itself provided enough information to find a solution for this issue.

Reviewed By: shergin

Differential Revision: D24241147

Pulled By: sammy-SC

fbshipit-source-id: d5d632b49ca77b5d8be8b9c32358bef68f17d30a
brentvatne pushed a commit to expo/react-native that referenced this issue Dec 3, 2020
Summary:
This PR attempts to fix issue facebook#28278 and facebook#29525

On Crashlytics, the following error occurs in file `RCTWebSocketModule.m` at method `-[RCTWebSocketModule webSocket:didFailWithError:]` when a nil value is inserted into a dictionary as a value.

```
Fatal Exception: NSInvalidArgumentException
*** -[__NSPlaceholderDictionary initWithObjects:forKeys:count:]: attempt to insert nil object from objects[0]
```

This PR is following the suggestion of this: facebook#28278 (comment) and it replaces the values of any property if it is nil. In detail:
- it converts `error` to empty NSString if the original value is nil
- it converts `socketID` to a NSNumber object, which stores `-1` if the original value is nil

## Changelog

[iOS] [Fixed] - A crash in WebSocket module

Pull Request resolved: facebook#30066

Test Plan: We were not able to reproduce the crash, but the report itself provided enough information to find a solution for this issue.

Reviewed By: shergin

Differential Revision: D24241147

Pulled By: sammy-SC

fbshipit-source-id: d5d632b49ca77b5d8be8b9c32358bef68f17d30a
@facebook facebook locked as resolved and limited conversation to collaborators Oct 1, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Needs: Attention Issues where the author has responded to feedback. Needs: Repro This issue could be improved with a clear list of steps to reproduce the issue. Stale There has been a lack of activity on this issue and it may be closed soon.
Projects
None yet
Development

No branches or pull requests

5 participants