Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error 1016 when executing Argo Tunnel from Node child_process

Cloudflare Argo Tunnel from Node child_process

I have an electron app from which I would like to spawn a child process that executes

cloudflared tunnel --url localhost:3000

inside a certain directory. Executing this from cmd inside that directory instantiates the argo tunnel as expected, and the url works while the process is running. This is how I am executing the command from the electron app:

const { spawn } = require('child_process')

let tunnel = spawn('cloudflared', ['tunnel', '--url', 'localhost:4000'], {
  stdio: 'inherit', // Will use process .stdout, .stdin, .stderr
  cwd: 'c://cloudflare'
})

I can see the normal console output from cloudflare indicating that the tunnel has been established and my server is responding at some-random-name.trycloudflare.com. However, when the process is started from within the electron app, I get Error 1016 displayed on a cloudflare error page.

Does anyone have experience with Argo Tunnel and child_process?

like image 878
Nathan Fries Avatar asked Aug 28 '19 06:08

Nathan Fries


2 Answers

I was able to get your setup to work on my Mac without issue, so you need to look further into the details of your setup. Here is what I did:

  1. Installed Electron Fiddle v0.9.0 from GitHub
  2. Installed cloudflared version 2019.8.4 via homebrew with
    brew install cloudflare/cloudflare/cloudflared
    
  3. From the command line (Terminal window), ran
    cloudflared tunnel --url localhost:3000
    
    cloudflared had some complaints:
    • Cannot determine default configuration path. No file [config.yml config.yaml] in [~/.cloudflared ~/.cloudflare-warp ~/cloudflare-warp /usr/local/etc/cloudflared /etc/cloudflared]

    • cloudflared will not automatically update when run from the shell

    • unable to connect to the origin error="Get http://localhost:3000: dial tcp [::1]:3000: connect: connection refused"

  4. Started a web server on localhost:3000 with
    python -m SimpleHTTPServer 3000
    
  5. Loaded the page http://localhost:3000 in my browser
  6. Again ran
    cloudflared tunnel --url localhost:3000
    
    Same complaints, except this time it was able to connect:

    Proxying tunnel requests to http://localhost:3000

  7. Further output from cloudflared indicated it was bringing up 4 tunnels. For each tunnel, it output

    +-----------------------------------------------------------+
    |  Your free tunnel has started! Visit it:                  |
    |    https://sides-universe-gym-metadata.trycloudflare.com  |
    +-----------------------------------------------------------+
    Route propagating, it may take up to 1 minute for your new route to become functional
    

    Note that I did not change or obfuscate the URL, that is exactly what was output, and cloudflared output the same URL 4 times, once for each tunnel.

  8. I went to https://sides-universe-gym-metadata.trycloudflare.com and verified it displayed the same website I had brought up on localhost:3000.

  9. I quit cloudflared by typing ctrl-c in the Terminal window where it was running. It took quite some time to shut down, but I waited until it quit.

  10. I went to https://sides-universe-gym-metadata.trycloudflare.com and verified it displayed an error. It displayed "Error 1016" and "Origin DNS error".

  11. In Electron Fiddle, I selected Electron v6.0.6 and used the default, pre-installed main.js, index.html, and renderer.js. In main.js, I added at the bottom

    const { spawn } = require('child_process')
    
    let tunnel = spawn('cloudflared', ['tunnel', '--url', 'localhost:3000'], {
      stdio: 'inherit', // Will use process .stdout, .stdin, .stderr
      cwd: '/Users/user/development'
    })
    
    
  12. I clicked "Run" on Electron Fiddle. The "Hello World!" page came up. The Electron Console showed output from cloudflared.
    • Again cloudflared brought up 4 tunnels, each with the URL https://citysearch-celebs-generator-history.trycloudflare.com
    • cloudflared then logged:
    • cloudflared has been updated to version 2019.8.4

    • PID of the new process is 81076

    • Quitting...

    • Metrics server stopped

    • I have no idea why it "updated" from "2019.8.4" to "2019.8.4". Maybe it has something to do with not having a default configuration, maybe it had something to do with Electron Fiddle running it from a non-standard location. I suspect it is because the command line did not include --is-autoupdated=true.
    • Immediately after "Metrics server stopped" cloudflared started logging its startup messages, just as before.
    • Again it brought up 4 tunnels, this time with URL https://gifts-jpg-treasury-correct.trycloudflare.com
    • Total time elapsed from start through restart to last stable tunnel up: 14 seconds.
  13. I went to https://gifts-jpg-treasury-correct.trycloudflare.com in my local browser and again got the site I was hosting at localhost:3000.
  14. I hit "Stop" in Electron. The Electron server stopped, but cloudflared kept running. I could still load https://gifts-jpg-treasury-correct.trycloudflare.com/
  15. I hit "Run" in Electron. Again cloudflared brought up 4 tunnels. This time it did not auto-update or restart. The 4 new tunnels all had the same new URL: https://reject-pride-built-twisted.trycloudflare.com/
  16. I went to https://reject-pride-built-twisted.trycloudflare.com/ in my local browser and again got the site I was hosting at localhost:3000. I tried https://gifts-jpg-treasury-correct.trycloudflare.com and it, too, was still working.

So I cannot reproduce your problem. Possible issues are that you may have been looking at the first tunnel that came up but cloudflared had updated, closed that tunnel, and started a different one. This worked for me on Mac but it seems you are working on Windows so it could be some Windows-specific issue. It could be that you do not have a server running on localhost:4000 or that your Electron app cannot access C://clouflare.

You need to provide more information, such as the log output of your Electron app running cloudflared and details about the server running at localhost:4000 and any cloudflared configuration files you have set up.

like image 56
Old Pro Avatar answered Nov 15 '22 06:11

Old Pro


Common cause
Cloudflare cannot resolve the origin web server’s IP address.

Common causes for Error 1016 are:

A missing DNS A record that mentions the origin IP address. A CNAME record in Cloudflare DNS points to an unresolvable external domain. The origin host names (CNAMEs) in your Cloudflare Load Balancer default, region, and fallback pools are unresolvable. Use a fallback pool configured with an origin IP as a backup in case all other pools are unavailable. Resolution

To resolve error 1016:

1) Verify your Cloudflare DNS settings include an A record that points to a valid IP address that resolves via a DNS lookup tool.
2) For a CNAME record pointing to a different domain, ensure that the target domain resolves via a DNS lookup tool.

like image 44
Pushprajsinh Chudasama Avatar answered Nov 15 '22 04:11

Pushprajsinh Chudasama