Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d203f52

Browse files
authored
fix: Port forward should ignore coder ports (coder#7645)
Ports opened by coder agent should be ignored in the listening ports map.
1 parent cd416c8 commit d203f52

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed

cli/agent.go

+6-8
Original file line numberDiff line numberDiff line change
@@ -125,18 +125,20 @@ func (r *RootCmd) workspaceAgent() *clibase.Cmd {
125125
_ = pprof.Handler
126126
pprofSrvClose := ServeHandler(ctx, logger, nil, pprofAddress, "pprof")
127127
defer pprofSrvClose()
128-
// Do a best effort here. If this fails, it's not a big deal.
129-
if port, err := urlPort(pprofAddress); err == nil {
128+
if port, err := extractPort(pprofAddress); err == nil {
130129
ignorePorts[port] = "pprof"
131130
}
132131

133132
prometheusSrvClose := ServeHandler(ctx, logger, prometheusMetricsHandler(), prometheusAddress, "prometheus")
134133
defer prometheusSrvClose()
135-
// Do a best effort here. If this fails, it's not a big deal.
136-
if port, err := urlPort(prometheusAddress); err == nil {
134+
if port, err := extractPort(prometheusAddress); err == nil {
137135
ignorePorts[port] = "prometheus"
138136
}
139137

138+
if port, err := extractPort(debugAddress); err == nil {
139+
ignorePorts[port] = "debug"
140+
}
141+
140142
// exchangeToken returns a session token.
141143
// This is abstracted to allow for the same looping condition
142144
// regardless of instance identity auth type.
@@ -225,10 +227,6 @@ func (r *RootCmd) workspaceAgent() *clibase.Cmd {
225227

226228
debugSrvClose := ServeHandler(ctx, logger, agnt.HTTPDebug(), debugAddress, "debug")
227229
defer debugSrvClose()
228-
// Do a best effort here. If this fails, it's not a big deal.
229-
if port, err := urlPort(debugAddress); err == nil {
230-
ignorePorts[port] = "debug"
231-
}
232230

233231
<-ctx.Done()
234232
return agnt.Close()

cli/agent_internal_test.go

+6
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,12 @@ func Test_extractPort(t *testing.T) {
4646
urlString: "6060",
4747
wantErr: true,
4848
},
49+
{
50+
name: "127.0.0.1",
51+
urlString: "127.0.0.1:2113",
52+
want: 2113,
53+
wantErr: false,
54+
},
4955
}
5056
for _, tt := range tests {
5157
tt := tt

0 commit comments

Comments
 (0)