Javascript 使用react本机应用程序随机挂起获取请求
前几天,我注意到应用程序的一些API调用没有被静默地执行。在Javascript 使用react本机应用程序随机挂起获取请求,javascript,ruby-on-rails,react-native,networking,actioncable,Javascript,Ruby On Rails,React Native,Networking,Actioncable,前几天,我注意到应用程序的一些API调用没有被静默地执行。在fetch请求之前和之后,我注销了一个console.log,瞧,fetch上的等待从未完成 // in an async js function... let response; try { console.log("START") response = await fetch(url, { headers, method, body }); console.log("END"
fetch
请求之前和之后,我注销了一个console.log,瞧,fetch上的等待从未完成
// in an async js function...
let response;
try {
console.log("START")
response = await fetch(url, { headers, method, body });
console.log("END")
} catch (err) {
console.log(err)
}
会结束吗?
在应用程序的日志中,我看到“开始”,但我等待2-5分钟,它通常会打印“结束”
是服务器吗?
我怀疑这只是一个缓慢的服务器API,但跟踪服务器上的日志,请求直到“开始”后2分钟才被发送——我看到它在打印“结束”时被正确发送/处理
我将actioncable连接到Redis,安装在我的Rails应用程序中,通过Heroku上的Puma提供服务
我可以复制它吗?
复制它非常困难,但我通常可以通过在iOS应用程序模拟器中按下command+R
来触发它,这会重新加载应用程序,并启动一些挂起的新API请求
还有什么吗?
我打开了与服务器的websocket连接。不确定这是否会造成任何干扰
我尝试使用AbortController的超时,但它只等待5秒,然后终止请求(但没有新请求成功)
一旦启动,每个API请求都会挂起
我的问题
traceroute to us-east-1-a.route.herokuapp.com (127.0.0.54), 64 hops max, 52 byte packets
1 * * *
2 * * *
3 * * *
4 * * *
5 * * *
6 * * *
7 * * *
8 * * *
9 * * *
10 * * *
(it never ends)
curl -v https://redacted.herokuapp.com/v3/users/me
* Trying 127.0.0.54...
* TCP_NODELAY set
* Connection failed
* connect to 127.0.0.54 port 443 failed: Operation timed out
* Failed to connect to redacted.herokuapp.com port 443: Operation timed out
* Closing connection 0
curl: (7) Failed to connect to redacted.herokuapp.com port 443: Operation timed out
- 有什么好方法可以调试这个吗
- 在后台是否存在我不知道的正在排队获取请求的情况
curl
请求和一个traceroute
,结果他们发现有什么东西一直挂着
跟踪路由结果
traceroute to us-east-1-a.route.herokuapp.com (127.0.0.54), 64 hops max, 52 byte packets
1 * * *
2 * * *
3 * * *
4 * * *
5 * * *
6 * * *
7 * * *
8 * * *
9 * * *
10 * * *
(it never ends)
curl -v https://redacted.herokuapp.com/v3/users/me
* Trying 127.0.0.54...
* TCP_NODELAY set
* Connection failed
* connect to 127.0.0.54 port 443 failed: Operation timed out
* Failed to connect to redacted.herokuapp.com port 443: Operation timed out
* Closing connection 0
curl: (7) Failed to connect to redacted.herokuapp.com port 443: Operation timed out
卷曲结果
traceroute to us-east-1-a.route.herokuapp.com (127.0.0.54), 64 hops max, 52 byte packets
1 * * *
2 * * *
3 * * *
4 * * *
5 * * *
6 * * *
7 * * *
8 * * *
9 * * *
10 * * *
(it never ends)
curl -v https://redacted.herokuapp.com/v3/users/me
* Trying 127.0.0.54...
* TCP_NODELAY set
* Connection failed
* connect to 127.0.0.54 port 443 failed: Operation timed out
* Failed to connect to redacted.herokuapp.com port 443: Operation timed out
* Closing connection 0
curl: (7) Failed to connect to redacted.herokuapp.com port 443: Operation timed out
更新:这变得越来越奇怪。我关掉了iOS模拟器,让电脑休息10分钟。回来后,只是尝试了简单的curl请求,结果成功了。启动iOS模拟器备份,现在我的curl请求超时
更新:我怀疑这与Heroku上的actioncable阻止请求有关。正在尝试禁用所有WebSocket并再次测试
更新:为了查看它是否是特定于应用程序的,我创建了一个全新的react原生应用程序和一个全新的Rails API API步骤
traceroute to us-east-1-a.route.herokuapp.com (127.0.0.54), 64 hops max, 52 byte packets
1 * * *
2 * * *
3 * * *
4 * * *
5 * * *
6 * * *
7 * * *
8 * * *
9 * * *
10 * * *
(it never ends)
curl -v https://redacted.herokuapp.com/v3/users/me
* Trying 127.0.0.54...
* TCP_NODELAY set
* Connection failed
* connect to 127.0.0.54 port 443 failed: Operation timed out
* Failed to connect to redacted.herokuapp.com port 443: Operation timed out
* Closing connection 0
curl: (7) Failed to connect to redacted.herokuapp.com port 443: Operation timed out
- rails新的my_api——api
- 删除sqlite3并添加到pg gem中
- 更新的database.yml
- 添加“健康”状态ok端点(控制器+路由)
- 部署到heroku
traceroute to us-east-1-a.route.herokuapp.com (127.0.0.54), 64 hops max, 52 byte packets
1 * * *
2 * * *
3 * * *
4 * * *
5 * * *
6 * * *
7 * * *
8 * * *
9 * * *
10 * * *
(it never ends)
curl -v https://redacted.herokuapp.com/v3/users/me
* Trying 127.0.0.54...
* TCP_NODELAY set
* Connection failed
* connect to 127.0.0.54 port 443 failed: Operation timed out
* Failed to connect to redacted.herokuapp.com port 443: Operation timed out
* Closing connection 0
curl: (7) Failed to connect to redacted.herokuapp.com port 443: Operation timed out
- 创建新的本地应用程序
- 在
中添加一个setInterval请求,以从rails API获取数据componentDidMount
- 在等待前后放置一个console.log
- 按控制台上的刷新(“r”)刷新应用程序
- 刷新应用程序约10次
- 请求在某个点挂起