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 Error Socket is not connected when reopen app after a push notification #245

Closed
thierryfornetti opened this issue Apr 14, 2017 · 4 comments

Comments

@thierryfornetti
Copy link

Hello, I’m making an App with React Native that use a chat and push notifications.
Only for ios, I keep getting an error 'The operation couldn’t be completed. Socket is not connected' when the app is reopened after I received a Push notification. I use websocket for the chat, I close it when the app goes in background and reopen it when the app gets active again (by using AppState), but appearently before the app became active there are some operations on the socket, and since it’s closed I get an error. This is the log from xCode when I open the app

2017-04-03 16:42:31.222990 myAwesomeApp[391:47603] [] nw_socket_get_input_frames recvmsg(fd 14, 4096 bytes): [57] Socket is not connected
2017-04-03 16:42:31.224205 myAwesomeApp[391:47603] [] nw_socket_get_input_frames recvmsg(fd 7, 1024 bytes): [57] Socket is not connected
2017-04-03 16:42:31.256966 myAwesomeApp[391:47603] [] nw_socket_write_close shutdown(14, SHUT_WR): [57] Socket is not connected
2017-04-03 16:42:31.257133 myAwesomeApp[391:47603] [] nw_endpoint_flow_service_writes [11 10.131.184.151:3000 ready socket-flow (satisfied)] Write request has 0 frame count, 0 byte count
2017-04-03 16:42:31.259241 myAwesomeApp[391:47603] [] nw_endpoint_handler_add_write_request [1.1 104.16.207.165:443 failed socket-flow (satisfied)] cannot accept write requests
2017-04-03 16:42:31.259682 myAwesomeApp[391:48142] [] __tcp_connection_write_eof_block_invoke Write close callback received error: [89] Operation canceled
2017-04-03 16:42:31.270016 myAwesomeApp[391:48142] [] __tcp_connection_write_eof_block_invoke Write close callback received error: [22] Invalid argument

2017-04-03 16:42:31.371 [info][tid:com.facebook.react.JavaScript] 'Websocket onerror ', 'closed'
2017-04-03 16:42:31.371402 myAwesomeApp[391:47546] 'Websocket onerror ', 'closed'
2017-04-03 16:42:31.374 [info][tid:com.facebook.react.JavaScript] 'catchServerErrorModal This is the websocket error', 'The operation couldn’t be completed. Socket is not connected'
2017-04-03 16:42:31.374452 myAwesomeApp[391:47546] 'catchServerErrorModal This is the websocket error', 'The operation couldn’t be completed. Socket is not connected'
2017-04-03 16:42:31.382 [info][tid:com.facebook.react.JavaScript] AppContainer render

I have no idea of what is logging those first lines. They seems operation on the socket that happen before I receive a notification of state "active". They're working on the socket that I closed when the app went in background, so of course I get a crash.
Anyway, the socket get recreated correctly, even if there is this error, when the app gets active it create a new socket and everything works fine.

This error happens only on certain conditions:

  • the app is in background, the screen is locked, I get a notification and open the app (with the notification or by clicking the app icon). Error
  • the app is in background, lock the screen, unlock the screen, I get a notification with the screen unlocked, open the app (with the notification or by clicking the app icon). Error
  • the app is in background, I get a notification with the screen unlocked, open the app. No Error
  • kill the app (double click on Home button), lock the screen, I get a notification and open the app (with the notification or by clicking the app icon). No Error
  • the app is in background, the screen is locked, open the app (no notification). No Error

As you see it seems related to push notification and the screen locked.

After adding some logs inside the classes I got a more complete logs, but I still don’t know what are those logs nw_socket_*
myChat ios logs - Crash on open notification.txt

What I’m using:
React Native 0.38
One Signal 3.0.3
Device iPhone5 iOS 10.1.1
xCode 8.3.1

Thanks for the help

@avishayil
Copy link
Contributor

Hi @thierryfornetti , could you share a repo with your code?

@thierryfornetti
Copy link
Author

Hello @avishayil, unfortunately I can't share my code, when I have some time (and right now I don't) I'll try to create a little app that reproduce the error.
Anyway I don't think it's a problem of my code, since there are operations done before my app return in foreground.
Could it be a problem about the way I close my socket? It's pretty simple so I don't think that's the case.

index.ios.js

_handleAppStateChange = (currentAppState) => {
    ...
    if (currentAppState === "inactive"){
        this.props.closeWebsocket()
    }
}

actions/websocket.js

function closeWebsocket(){
    ...
    socket.send(unsubscribe_command)
    ...
    socket.close()
}

Also, why it happens when I lock the screen and it doesn't when the app is just in background?
As I said, it's probably something on the native library and RCTWebsocket.

@Nightsd01
Copy link
Contributor

@thierryfornetti Closing this issue due to inactivity. Apologies for the delayed response. I have seen this error with just react-native itself (not using web sockets in my own application).

If you are still encountering this issue, please feel free to respond and I would be happy to reopen and investigate the problem.

@fabdrol
Copy link

fabdrol commented May 11, 2018

I'm running into this issue as well, anyone ever figured out what caused it? Here's what I do:

Thoughts?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants