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

My Phone can't download JS bundle because of error - Failed to connect to /127.0.0.1:10000 #34

Open
puresprout opened this issue Nov 1, 2024 · 9 comments

Comments

@puresprout
Copy link

Hello!

azurite, code-push server, CLI, and applying the code-push module to the React Native app
are completed.

And I bundled the JS code for the update and released the update content through the CLI.

So when I ran the app, I checked if there was a JS update code as follows.
And Update Popup is shown up

[05:00:15] Loading JS bundle from "assets://index.android.bundle"
[05:00:16] Sync already in progress.
[05:00:16] Checking for update.
[05:00:16] Awaiting user action.

However, when I try to install by clicking the install button, I get the following error.

[05:02:42] Downloading package.
[05:02:42] Exception
[05:02:42] An unknown error occurred. [05:02:42] Failed to connect to /127.0.0.1:10000

That is, My Real Phone requests a download to the address 127.0.0.1:10000, but from My Phone's perspective, 127.0.0.1 is the My Phone itself, so an error occurs.
How can I make requests come in to the code-push server for the local PC?

How should I set up the code-push server?
The code-push server document does not have any part for setting the azurite server address.
(It seems to be set only to the default IP and default port.)
(I tried setting the AZURE_STORAGE_CONNECTION_STRING environment variable in the api/.env file, but it does not apply at all.)

Or how should I set up azurite?

Please help.

@DavidKostDev

@gkanishk
Copy link

gkanishk commented Nov 4, 2024

@puresprout I was also facing same issue while integrating codepush locally, in case of actual device you'll need to point it to device ip and in case of emulator it should be 10.0.2.2

I did some changes in node_modules/react-native-code-push/android/app/src/main/java/com/microsoft/codepush/react/CodePushUpdateManager.java this file inside downloadPackage function

String downloadUrlString = updatePackage.optString(CodePushConstants.DOWNLOAD_URL_KEY, null).replace("127.0.0.1", "10.0.2.2");

if you're running in actual device then add you laptop or server local ip (replace 10.0.2.2 with host ip something like 192.168.x.x) post that create new apk. This hack works for local setup.

@puresprout
Copy link
Author

puresprout commented Nov 6, 2024

@gkanishk
Hello

I tried the way you suggested. The log output is as follows.

[04:08:12] Checking for update.
[04:08:12] Reporting binary update (0.0.1)
[04:08:13] Awaiting user action.
[04:19:32] Downloading package.
[04:19:32] Applying full update.
[04:19:32] Installing update.
[04:19:32] Update is installed and will be run on the next app restart.
[04:23:36] Checking for update.

The actual download went well and related information was recorded in the phone's data directory as shown below.

/data/data/{appPackageName}/files/CodePush/bc5b6556251d2211946d39846651cbceb8f557941a725a9b23a2f49c4dea48ea/app.json

When I restart the app, the updates still aren't applied.

For reference, the app was launched by pressing a button with the npm start command and the update check and download went through just fine, but the updates were not applied when the app was restarted. That is, I used a debug build.

I was wondering if I should do a release build, so I did the following, but even the update check didn't work in release mode.

[04:51:11] Loading JS bundle from "assets://index.android.bundle"
[04:51:11] Checking for update.
[04:51:11] Reporting binary update (0.0.1)
[04:51:11] Report status failed: {"appVersion":"0.0.1"}
[04:51:11] An unknown error occurred.
[04:51:11] Network request failed
[04:51:11] Reporting binary update (0.0.1)
[04:51:11] Report status failed: {"appVersion":"0.0.1"}

Please help me.

Did you successfully check for updates, download them, and apply the updates when you restarted the app?
@gkanishk @DavidKostDev

@gkanishk
Copy link

gkanishk commented Nov 6, 2024

@puresprout what logs are you seeing in android device?
For me all the flows are working fine on emulator, After download and restart new bundle is being served.

can you try doing same change while Report status call? might be status call be hitting 127.0.0.1

@puresprout
Copy link
Author

I tested it further.

I built it in release mode on my actual phone and ran it, but in release mode, http requests are blocked, so a network error occurs.

So I added the following settings and tested it again, and everything went well, including the apply of the app update.

# android/app/src/main/AndroidManifest.xml
    <application
        android:usesCleartextTraffic="true"
 
 
# result - success
[06:09:33] Loading JS bundle from "assets://index.android.bundle"
[06:09:33] Checking for update.
[06:09:33] Reporting binary update (0.0.1)
[06:09:33] Awaiting user action.
[06:09:38] Downloading package.
[06:09:38] Applying full update.
[06:09:38] Installing update.
[06:09:38] Update is installed and will be run on the next app restart.
[06:09:44] Loading JS bundle from "/data/user/0/{appPackageName}/files/CodePush/{}/CodePush/index.android.bundle"
[06:09:44] Sync already in progress.
[06:09:44] Checking for update.
[06:09:44] Reporting CodePush update success (v1)
[06:09:44] App is up to date.

Everything works. Thanks

@gkanishk

@Irfanwani
Copy link

Irfanwani commented Nov 9, 2024

I am getting this on client side

 An unknown error occurred.
404: No deployment found.

And on the server side, I get this error

Are you using a Stream of unknown length as the Body of a PutObject request? Consider using Upload instead from @aws-sdk/lib-storage.
An error was encountered in a non-retryable streaming request.
Unknown error source
NotImplemented: A header you provided implies functionality that is not implemented
at throwDefaultError (/code-push-server/api/node_modules/@smithy/smithy-client/dist-cjs/index.js:836:20)
at /code-push-server/api/node_modules/@smithy/smithy-client/dist-cjs/index.js:845:5
at de_CommandError (/code-push-server/api/node_modules/@aws-sdk/client-s3/dist-cjs/index.js:4739:14)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async /code-push-server/api/node_modules/@smithy/middleware-serde/dist-cjs/index.js:35:20
at async /code-push-server/api/node_modules/@aws-sdk/middleware-sdk-s3/dist-cjs/index.js:485:18
at async /code-push-server/api/node_modules/@smithy/middleware-retry/dist-cjs/index.js:320:38
at async /code-push-server/api/node_modules/@aws-sdk/middleware-flexible-checksums/dist-cjs/index.js:263:18
at async /code-push-server/api/node_modules/@aws-sdk/middleware-sdk-s3/dist-cjs/index.js:110:22
at async /code-push-server/api/node_modules/@aws-sdk/middleware-sdk-s3/dist-cjs/index.js:138:14

BTW i am using this fork of this repo as i wanted to use AWS instead of azure

@ahsanparacha02
Copy link

@puresprout I have debugged the app locally on my real device, but CodePush is not detecting the bundle file. Below are the logs and code push release.
Can you provide the steps you followed to set up the app locally and also release version of the app.

Image
Image

@puresprout
Copy link
Author

@ahsanparacha02

2 style works.

# all binary targeting. artifact into CodePushDirName. develop deployment. => works
code-push-standalone release my-app-android CodePushDirName "*" --deploymentName Develop

# => works
code-push-standalone release-react my-app-android android --deploymentName Develop

checks following

npm install --save react-native-code-push
 
# android/settings.gradle 
include ':app', ':react-native-code-push'
project(':react-native-code-push').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-code-push/android/app')
 
# android/app/build.gradle
apply from: "../../node_modules/react-native-code-push/android/codepush.gradle"
 
# android/app/src/main/java/com/kakaobank/kfrmApp/MainApplication.kt
import com.microsoft.codepush.react.CodePush
...
        object : DefaultReactNativeHost(this) {
            ...
            override fun getJSBundleFile(): String {
                return CodePush.getJSBundleFile()
            }
            ...
 
# android/app/src/main/res/values/strings.xml
    ...
    <string moduleConfig="true" name="CodePushDeploymentKey">{deploymentKey}</string>
    <string moduleConfig="true" name="CodePushServerUrl">http://SERVER_IP:PORT</string>
 
# src/App.tsx
...
const codePushOptions = {
    updateDialog: true,
    checkFrequency: CodePush.CheckFrequency.ON_APP_RESUME,
}
 
export default CodePush(codePushOptions)(App)

@amdrade
Copy link

amdrade commented Dec 7, 2024

`

LOG [CodePush] Sync already in progress.
LOG [CodePush] Checking for update.
LOG [CodePush] Awaiting user action.
LOG [CodePush] Downloading package.
LOG [CodePush] Installing update.
LOG [CodePush] Update is installed and will be run on the next app restart.

`

But not update bundle, after restart app.

@felixchan
Copy link

felixchan commented Dec 11, 2024

I'm having the same issue.

When I installed Standalone server , I enabled HTTPS and set my custom domain.

react-native-code-push successfully finds the newest package.

When I choose to actually update to newest package (run sync), I get:

nw_socket_handle_socket_event [C7:2] Socket SO_ERROR [61: Connection refused]
nw_endpoint_flow_failed_with_error [C7 127.0.0.1:10000 in_progress socket-flow (satisfied (Path is satisfied), interface: lo0)] already failing, returning
Connection 7: received failure notification
Connection 7: failed to connect 1:61, reason -1
Connection 7: encountered error(1:61)
nw_connection_copy_connected_local_endpoint_block_invoke [C7] Client called nw_connection_copy_connected_local_endpoint on unconnected nw_connection
nw_connection_copy_connected_remote_endpoint_block_invoke [C7] Client called nw_connection_copy_connected_remote_endpoint on unconnected nw_connection
Task <1E8D9052-4406-4970-8791-88540D222A8B>.<0> HTTP load failed, 0/0 bytes (error code: -1004 [1:61])
NSURLConnection finished with error - code -1004
'CODEPUSH STATUS', 3
[CodePush] Could not connect to the server.

Therefore, I try to replace server's downloadUrl generation with:

      updateCheckBody.updateInfo.downloadURL = updateCheckBody.updateInfo.downloadURL.replace(
          "http://127.0.0.1:10000",
          "http://api2.mydomain.com:10000"
        ); //inside acquisition.ts line 182

After this change, my client is able to see the correct downloadUrl domain.

I have made azurite --blobHost 0.0.0.0 so that it can listen. However, I'm still getting 404 (blob not found?)

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

6 participants