Description
This was a really interesting issue and really hard to catch.
We started to encounter this error which was crashing the app when doing a post request to the server:
console.log from .catch() of the fetch call.
{ [TypeError: Network request failed]
line: 25737,
column: 21,
sourceURL: 'http://localhost:8081/index.ios.bundle?platform=ios&dev=true' }
XCode console output:
[error] [tid:com.facebook.react.JavaScript] Network request failed
[error] [tid:com.facebook.react.JavaScript] Can't find variable: self
[fatal] [tid:com.facebook.react.RCTExceptionsManagerQueue] Unhandled JS Exception: Network request failed
[fatal][tid:com.facebook.react.RCTExceptionsManagerQueue] Unhandled JS Exception: Can't find variable: self
Communications error: <OS_xpc_error: <error: 0x5a00534> { count = 1, contents = "XPCErrorDescription" => <string: 0x5a00734> { length = 22, contents = "Connection interrupted" } } >
One weird thing is that the first request always throws this error but from the second request everything works fine.
After a long day investigating it we discovered that is related to the HTTP/2 feature
It used to work before, but Chrome deprecated the old way it worked on May 15 and it was de-facto disabled since then.
We've reenabled it by upgrading out openresty which is based on NGINX 1.9.15, but apparently react-native can't handle the upgraded version, which sucks ass.
It will be a pain in the ass to reproduce it since you need OpenSSL 1.0.2, that means the most recent Ubuntu - 16.04, because previous versions are stuck on OpenSSL 1.0.1.
We're running Ubuntu 14.04, so I had to compile OpenSSL from source to make it work.
I saw that on release 0.27 of react-native you guys cherry picked this commit ( 6bbaff2 ) which is related somehow but in the description of the issue ( #4021) that motivated the commit the problem was only for Android however we experienced this in both platforms ( iOS and Android ).
Activity
[-] Network request failed when HTTP/2 enabled on iOS and Android[/-][+] [iOS and Android] Network request failed when HTTP/2 enabled.[/+]ide commentedon Jun 9, 2016
On Android there is a known problem with OkHttp and should get better once some upstream issues with OkHttp allow us to use a newer version of OkHttp in RN: #7746.
On iOS I don't think we've seen issues yet but thanks for the report. We should fix the JS bug that causes "Can't find variable: self", but
Communications error: <OS_xpc_error>may be out of our control and the best way to get that fixed is to figure out the bug in iOS and open a bug report with Apple.xiaoneng commentedon Jun 13, 2016
Similar #7943
ryankask commentedon Jul 28, 2016
Are the servers all using nginx 1.10.X?
This is probably related to https://trac.nginx.org/nginx/ticket/959
I'm experiencing this on iOS and after adding some debugging in the RN networking internals I saw I was getting error -1004. That led me to this: http://stackoverflow.com/questions/36907767/nsurlerrordomain-code-1004-for-few-seconds-after-app-start-up and then to the nginx issue referred to above.
lacker commentedon Oct 28, 2016
Looks like this has been fixed