cloudflare / workers-sdk

โ›…๏ธ Home to Wrangler, the CLI for Cloudflare Workersยฎ
https://developers.cloudflare.com/workers/
Apache License 2.0
2.66k stars 696 forks source link

๐Ÿ› BUG: Support http proxies for `wrangler dev` #1738

Closed tianluanchen closed 2 years ago

tianluanchen commented 2 years ago

What version of Wrangler are you using?

2.0.22

What operating system are you using?

windows 10

Describe the Bug

wrangler pages publish public --project-name xxxx              

X [ERROR] fetch failed

If you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new/choose 

Logging in is fine, but when posting a project it fails to capture, setting the http proxy is useless, even though the http proxy allows the browser to open all websites normally

rozenmd commented 2 years ago

Hi @tianluanchen, could you please clarify what you mean by "setting the http proxy is useless"? Is there an error message?

What steps did you take to setup the http proxy?

Lifeni commented 2 years ago

I had the same problem. I want to run a worker, but it says fetch failed.

cross-env HTTP_PROXY=http://127.0.0.1:7890 wrangler dev
 โ›…๏ธ wrangler 2.0.27 
--------------------
โฌฃ Listening at http://0.0.0.0:8787
TypeError: fetch failed
    at Object.processResponse (C:\Users\Liang\Desktop\้กน็›ฎ\็ป„็ป‡\Coding\workers\node_modules\.pnpm\wrangler@2.0.27\node_modules\wrangler\wrangler-dist\cli.js:70321:27)
    at C:\Users\Liang\Desktop\้กน็›ฎ\็ป„็ป‡\Coding\workers\node_modules\.pnpm\wrangler@2.0.27\node_modules\wrangler\wrangler-dist\cli.js:70654:42
    at node:internal/process/task_queues:141:7
    at AsyncResource.runInAsyncScope (node:async_hooks:202:9)
    at AsyncResource.runMicrotask (node:internal/process/task_queues:138:8)
    at processTicksAndRejections (node:internal/process/task_queues:96:5) {
  cause: [Error: 23128:error:1408F10B:SSL routines:ssl3_get_record:wrong version number:c:\ws\deps\openssl\openssl\ssl\record\ssl3_record.c:332:
  ] {
    library: 'SSL routines',
    function: 'ssl3_get_record',
    reason: 'wrong version number',
    code: 'ERR_SSL_WRONG_VERSION_NUMBER'
  }
}
Something went wrong:                                                                                          
TypeError: fetch failed                                                                                        
    at Object.processResponse (C:\Users\Liang\Desktop\้กน็›ฎ\็ป„็ป‡\Coding\workers\node_modules\.pnpm\wrangler@2.0.
27\node_modules\wrangler\wrangler-dist\cli.js:70321:27)
    at C:\Users\Liang\Desktop\้กน็›ฎ\็ป„็ป‡\Coding\workers\node_modules\.pnpm\wrangler@2.0.27\node_modules\wrangler
\wrangler-dist\cli.js:70654:42
    at node:internal/process/task_queues:141:7
    at AsyncResource.runInAsyncScope (node:async_hooks:202:9)
    at AsyncResource.runMicrotask (node:internal/process/task_queues:138:8)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)

X [ERROR] fetch failed

If you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new/choose

The OS version is Windows 11 and the wrangler version is 2.0.27.

rozenmd commented 2 years ago

@Lifeni - do you mind trying something for me?

Does it work if you try run:

cross-env HTTPS_PROXY=http://127.0.0.1:7890 wrangler dev

?

Lifeni commented 2 years ago

@rozenmd It still doesn't work, the error message is the same as before (ERR_SSL_WRONG_VERSION_NUMBER).

But the error message sometimes becomes Error: read ECONNRESET or Error: Client network socket disconnected before secure TLS connection was established. This may be related to my bad network, I will try again after a while.

rozenmd commented 2 years ago

@Lifeni - so it's a bug, wrangler dev doesn't handle proxies correctly, wrangler dev --local should work though

Can you confirm whether other wrangler commands work, like wrangler publish and wrangler whoami?

Lifeni commented 2 years ago

@rozenmd

Two days ago, neither wrangler dev nor wrangler publish worked properly, only wrangler dev would give detailed error messages.

After that, I changed my proxy software. wrangler publish and wrangler whoami seem to work fine, but wrangler dev still doesn't work. Unlike before, it prompts that the upload is complete, but fails to load the page. Below is the new error message.

Run `wrangler dev` ``` > wrangler dev โ›…๏ธ wrangler 2.0.28 -------------------- Retrieving cached values for userId from ..\..\node_modules\.cache\wrangler Your worker has access to the following bindings: - KV Namespaces: - urls: xxx โฌฃ Listening at http://0.0.0.0:8787 Total Upload: 15.82 KiB / gzip: 2.88 KiB โ•ญโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฎ โ”‚ [b] open a browser, [d] open Devtools, [l] turn on local mode, [c] clear console, [x] to exit โ”‚ โ•ฐโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฏ C:\Users\Liang\AppData\Roaming\fnm\node-versions\v16.16.0\installation\node_modules\wrangler\wrangler-dist\cli.js:12110 throw ex; ^ Error: connect ETIMEDOUT 199.59.148.9:443 at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1187:16) Emitted 'error' event on WebSocket3 instance at: at emitErrorAndClose (C:\Users\Liang\AppData\Roaming\fnm\node-versions\v16.16.0\installation\node_modules\wrangler\wrangler-dist\cli.js:116659:17) at ClientRequest. (C:\Users\Liang\AppData\Roaming\fnm\node-versions\v16.16.0\installation\node_modules\wrangler\wrangler-dist\cli.js:116565:9) at ClientRequest.emit (node:events:527:28) at TLSSocket.socketErrorListener (node:_http_client:454:9) at TLSSocket.emit (node:events:527:28) at emitErrorNT (node:internal/streams/destroy:157:8) at emitErrorCloseNT (node:internal/streams/destroy:122:3) at processTicksAndRejections (node:internal/process/task_queues:83:21) { errno: -4039, code: 'ETIMEDOUT', syscall: 'connect', address: '199.59.148.9', port: 443 } > curl -I 7653e5587bba444793d44fadfd7d0c7a.lifeni.workers.dev HTTP/1.1 404 Not Found Content-Length: 16 Alt-Svc: h3=":443"; ma=86400, h3-29=":443"; ma=86400 Cache-Control: private, max-age=0, no-store, no-cache, must-revalidate, post-check=0, pre-check=0 Cf-Ray: 74363a6ddb9f8eff-HKG Connection: keep-alive Content-Type: text/plain; charset=UTF-8 Date: Wed, 31 Aug 2022 13:49:13 GMT Expires: Thu, 01 Jan 1970 00:00:01 GMT Keep-Alive: timeout=4 Proxy-Connection: keep-alive Referrer-Policy: same-origin Server: cloudflare X-Frame-Options: SAMEORIGIN ```

I checked the url for the connection timeout and it is this: https://7653e5587bba444793d44fadfd7d0c7a.<name>.workers.dev/ (it changes every time). I can load it in the browser or curl.

So I think the previous problem is more likely a network problem. And there are still some issues with wrangler dev.

rozenmd commented 2 years ago

Thanks for that @Lifeni - we have a bug to fix for wrangler dev to make it support proxies - but does wrangler dev --local work?

Lifeni commented 2 years ago

@rozenmd wrangler dev --local works fine, thank you!

mehrab-wj commented 2 months ago

I still have this issue, on Windows 11, when using a proxy.

Unfortunately, none of the other options worked for me, so a quick fix for me was to change the Wrangler source code, in my node_modules ๐Ÿคฆ๐Ÿฝโ€โ™‚๏ธ

this was the error I got:

TypeError: Invalid URL
    at new URL (node:internal/url:804:36)
    at new ProxyAgent (C:\Users\mehrab\x\x\x\node_modules\wrangler\wrangler-dist\cli.js:10966:29)
    at Object.<anonymous> (C:\Users\mehrab\x\x\x\node_modules\wrangler\wrangler-dist\cli.js:203152:44)
    at Module._compile (node:internal/modules/cjs/loader:1368:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1426:10)
    at Module.load (node:internal/modules/cjs/loader:1205:32)
    at Module._load (node:internal/modules/cjs/loader:1021:12)
    at cjsLoader (node:internal/modules/esm/translators:366:17)
    at ModuleWrap.<anonymous> (node:internal/modules/esm/translators:315:7)
    at ModuleJob.run (node:internal/modules/esm/module_job:222:25) {
  code: 'ERR_INVALID_URL',
  input: '127.0.0.1:2080'
}

So I've changed wrangler\wrangler-dist\cli.js:203152 from this:

const resolvedUrl = new URL7(opts.uri);

to this:

const resolvedUrl = new URL7("http://" + opts.uri);