Skip to content

Commit 0034808

Browse files
authored
fix: infinite proxy loop (#4676)
I think the problem is that when a proxy is not in use proxy-agent returns the global agent...which is itself since we set it globally, causing the loop. VS Code already covers proxies meaning we only need to do it in our own requests so to fix this pass in the agent in the version fetch request instead of overidding globally. Also avoid proxy-from-env and pass in the proxy URI instead as both http_proxy and https_proxy can be used for either http or https requests but it does not allow that.
1 parent 47f0b6f commit 0034808

File tree

7 files changed

+41
-128
lines changed

7 files changed

+41
-128
lines changed

package.json

-1
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,6 @@
9292
"limiter": "^1.1.5",
9393
"pem": "^1.14.2",
9494
"proxy-agent": "^5.0.0",
95-
"proxy-from-env": "^1.1.0",
9695
"qs": "6.10.2",
9796
"rotating-file-stream": "^3.0.0",
9897
"safe-buffer": "^5.1.1",

src/node/constants.ts

+2
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,5 @@ export const rootPath = path.resolve(__dirname, "../..")
2525
export const vsRootPath = path.join(rootPath, "vendor/modules/code-oss-dev")
2626
export const tmpdir = path.join(os.tmpdir(), "code-server")
2727
export const isDevMode = commit === "development"
28+
export const httpProxyUri =
29+
process.env.HTTPS_PROXY || process.env.https_proxy || process.env.HTTP_PROXY || process.env.http_proxy

src/node/entry.ts

-3
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,9 @@ import { logger } from "@coder/logger"
22
import { optionDescriptions, parse, readConfigFile, setDefaults, shouldOpenInExistingInstance } from "./cli"
33
import { commit, version } from "./constants"
44
import { openInExistingInstance, runCodeServer, runVsCodeCli, shouldSpawnCliProcess } from "./main"
5-
import { monkeyPatchProxyProtocols } from "./proxy_agent"
65
import { isChild, wrapper } from "./wrapper"
76

87
async function entry(): Promise<void> {
9-
monkeyPatchProxyProtocols()
10-
118
// There's no need to check flags like --help or to spawn in an existing
129
// instance for the child process because these would have already happened in
1310
// the parent and the child wouldn't have been spawned. We also get the

src/node/proxy_agent.ts

-71
This file was deleted.

src/node/update.ts

+6-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import { field, logger } from "@coder/logger"
22
import * as http from "http"
33
import * as https from "https"
4+
import ProxyAgent from "proxy-agent"
45
import * as semver from "semver"
56
import * as url from "url"
6-
import { version } from "./constants"
7+
import { httpProxyUri, version } from "./constants"
78
import { SettingsProvider, UpdateSettings } from "./settings"
89

910
export interface Update {
@@ -102,8 +103,10 @@ export class UpdateProvider {
102103
return new Promise((resolve, reject) => {
103104
const request = (uri: string): void => {
104105
logger.debug("Making request", field("uri", uri))
105-
const httpx = uri.startsWith("https") ? https : http
106-
const client = httpx.get(uri, { headers: { "User-Agent": "code-server" } }, (response) => {
106+
const isHttps = uri.startsWith("https")
107+
const agent = httpProxyUri ? new ProxyAgent(httpProxyUri) : undefined
108+
const httpx = isHttps ? https : http
109+
const client = httpx.get(uri, { headers: { "User-Agent": "code-server" }, agent }, (response) => {
107110
if (!response.statusCode || response.statusCode < 200 || response.statusCode >= 400) {
108111
response.destroy()
109112
return reject(new Error(`${uri}: ${response.statusCode || "500"}`))

test/unit/node/proxy_agent.test.ts

-43
This file was deleted.

yarn.lock

+33-7
Original file line numberDiff line numberDiff line change
@@ -890,6 +890,11 @@ [email protected]:
890890
resolved "https://registry.yarnpkg.com/bytes/-/bytes-3.1.0.tgz#f6cf7933a360e0588fa9fde85651cdc7f805d1f6"
891891
integrity sha512-zauLjrfCG+xvoyaqLoV8bLVXXNGC4JqlxFCutSDWA6fJrTo2ZuvLYTqZ7aHBLZSMOopbzwv8f+wZcVzfVTI2Dg==
892892

893+
894+
version "3.1.1"
895+
resolved "https://registry.yarnpkg.com/bytes/-/bytes-3.1.1.tgz#3f018291cb4cbad9accb6e6970bca9c8889e879a"
896+
integrity sha512-dWe4nWO/ruEOY7HkUJ5gFt1DCFV9zPRoJr8pV0/ASQermOZjtq8jMjOprC0Kd10GLN+l7xaUPvxzJFWtxGu8Fg==
897+
893898
call-bind@^1.0.0, call-bind@^1.0.2:
894899
version "1.0.2"
895900
resolved "https://registry.yarnpkg.com/call-bind/-/call-bind-1.0.2.tgz#b1d4e89e688119c3c9a903ad30abb2f6a919be3c"
@@ -2190,7 +2195,18 @@ [email protected]:
21902195
statuses ">= 1.5.0 < 2"
21912196
toidentifier "1.0.0"
21922197

2193-
[email protected], http-errors@~1.7.2:
2198+
2199+
version "1.8.1"
2200+
resolved "https://registry.yarnpkg.com/http-errors/-/http-errors-1.8.1.tgz#7c3f28577cbc8a207388455dbd62295ed07bd68c"
2201+
integrity sha512-Kpk9Sm7NmI+RHhnj6OIWDI1d6fIoFAtFt9RLaTMRlg/8w49juAStsrBgp0Dp4OdxdVbRIeKhtCUvoi/RuAhO4g==
2202+
dependencies:
2203+
depd "~1.1.2"
2204+
inherits "2.0.4"
2205+
setprototypeof "1.2.0"
2206+
statuses ">= 1.5.0 < 2"
2207+
toidentifier "1.0.1"
2208+
2209+
http-errors@~1.7.2:
21942210
version "1.7.3"
21952211
resolved "https://registry.yarnpkg.com/http-errors/-/http-errors-1.7.3.tgz#6c619e4f9c60308c38519498c14fbb10aacebb06"
21962212
integrity sha512-ZTTX0MWrsQ2ZAhA1cejAwDLycFsd7I7nVtnkT3Ol0aqodaKW+0CTZDQ1uBv5whptCnc8e8HeRRJxRs0kmm/Qfw==
@@ -3459,7 +3475,7 @@ proxy-agent@^5.0.0:
34593475
proxy-from-env "^1.0.0"
34603476
socks-proxy-agent "^5.0.0"
34613477

3462-
proxy-from-env@^1.0.0, proxy-from-env@^1.1.0:
3478+
proxy-from-env@^1.0.0:
34633479
version "1.1.0"
34643480
resolved "https://registry.yarnpkg.com/proxy-from-env/-/proxy-from-env-1.1.0.tgz#e102f16ca355424865755d2c9e8ea4f24d58c3e2"
34653481
integrity sha512-D+zkORCbA9f1tdWRK0RaCR3GPv50cMxcrz4X8k5LTSUD1Dkw47mKJEZQNunItRTkWwgtaUSo1RVFRIG9ZXiFYg==
@@ -3512,12 +3528,12 @@ [email protected]:
35123528
unpipe "1.0.0"
35133529

35143530
raw-body@^2.2.0:
3515-
version "2.4.1"
3516-
resolved "https://registry.yarnpkg.com/raw-body/-/raw-body-2.4.1.tgz#30ac82f98bb5ae8c152e67149dac8d55153b168c"
3517-
integrity sha512-9WmIKF6mkvA0SLmA2Knm9+qj89e+j1zqgyn8aXGd7+nAduPoqgI9lO57SAZNn/Byzo5P7JhXTyg9PzaJbH73bA==
3531+
version "2.4.2"
3532+
resolved "https://registry.yarnpkg.com/raw-body/-/raw-body-2.4.2.tgz#baf3e9c21eebced59dd6533ac872b71f7b61cb32"
3533+
integrity sha512-RPMAFUJP19WIet/99ngh6Iv8fzAbqum4Li7AD6DtGaW2RpMB/11xDoalPiJMTbu6I3hkbMVkATvZrqb9EEqeeQ==
35183534
dependencies:
3519-
bytes "3.1.0"
3520-
http-errors "1.7.3"
3535+
bytes "3.1.1"
3536+
http-errors "1.8.1"
35213537
iconv-lite "0.4.24"
35223538
unpipe "1.0.0"
35233539

@@ -3817,6 +3833,11 @@ [email protected]:
38173833
resolved "https://registry.yarnpkg.com/setprototypeof/-/setprototypeof-1.1.1.tgz#7e95acb24aa92f5885e0abef5ba131330d4ae683"
38183834
integrity sha512-JvdAWfbXeIGaZ9cILp38HntZSFSo3mWg6xGcJJsd+d4aRMOqauag1C63dJfDw7OaMYwEbHMOxEZ1lqVRYP2OAw==
38193835

3836+
3837+
version "1.2.0"
3838+
resolved "https://registry.yarnpkg.com/setprototypeof/-/setprototypeof-1.2.0.tgz#66c9a24a73f9fc28cbe66b09fed3d33dcaf1b424"
3839+
integrity sha512-E5LDX7Wrp85Kil5bhZv46j8jOeboKq5JMmYM3gVGdGH8xFpPWXUMsNrlODCrkoxMEeNi/XZIwuRvY4XNwYMJpw==
3840+
38203841
shebang-command@^2.0.0:
38213842
version "2.0.0"
38223843
resolved "https://registry.yarnpkg.com/shebang-command/-/shebang-command-2.0.0.tgz#ccd0af4f8835fbdc265b82461aaf0c36663f34ea"
@@ -4238,6 +4259,11 @@ [email protected]:
42384259
resolved "https://registry.yarnpkg.com/toidentifier/-/toidentifier-1.0.0.tgz#7e1be3470f1e77948bc43d94a3c8f4d7752ba553"
42394260
integrity sha512-yaOH/Pk/VEhBWWTlhI+qXxDFXlejDGcQipMlyxda9nthulaxLZUNcUqFxokp0vcYnvteJln5FNQDRrxj3YcbVw==
42404261

4262+
4263+
version "1.0.1"
4264+
resolved "https://registry.yarnpkg.com/toidentifier/-/toidentifier-1.0.1.tgz#3be34321a88a820ed1bd80dfaa33e479fbb8dd35"
4265+
integrity sha512-o5sSPKEkg/DIQNmH43V0/uerLrpzVedkUh8tGNvaeXpfpuwjKenlSox/2O/BTlZUtEe+JG7s5YhEz608PlAHRA==
4266+
42414267
traverse@^0.6.6:
42424268
version "0.6.6"
42434269
resolved "https://registry.yarnpkg.com/traverse/-/traverse-0.6.6.tgz#cbdf560fd7b9af632502fed40f918c157ea97137"

0 commit comments

Comments
 (0)