mirror of https://github.com/coder/coder.git
fix: Port forward should ignore coder ports (#7645)
Ports opened by coder agent should be ignored in the listening ports map.
This commit is contained in:
parent
cd416c86dd
commit
d203f5259d
14
cli/agent.go
14
cli/agent.go
|
@ -125,18 +125,20 @@ func (r *RootCmd) workspaceAgent() *clibase.Cmd {
|
||||||
_ = pprof.Handler
|
_ = pprof.Handler
|
||||||
pprofSrvClose := ServeHandler(ctx, logger, nil, pprofAddress, "pprof")
|
pprofSrvClose := ServeHandler(ctx, logger, nil, pprofAddress, "pprof")
|
||||||
defer pprofSrvClose()
|
defer pprofSrvClose()
|
||||||
// Do a best effort here. If this fails, it's not a big deal.
|
if port, err := extractPort(pprofAddress); err == nil {
|
||||||
if port, err := urlPort(pprofAddress); err == nil {
|
|
||||||
ignorePorts[port] = "pprof"
|
ignorePorts[port] = "pprof"
|
||||||
}
|
}
|
||||||
|
|
||||||
prometheusSrvClose := ServeHandler(ctx, logger, prometheusMetricsHandler(), prometheusAddress, "prometheus")
|
prometheusSrvClose := ServeHandler(ctx, logger, prometheusMetricsHandler(), prometheusAddress, "prometheus")
|
||||||
defer prometheusSrvClose()
|
defer prometheusSrvClose()
|
||||||
// Do a best effort here. If this fails, it's not a big deal.
|
if port, err := extractPort(prometheusAddress); err == nil {
|
||||||
if port, err := urlPort(prometheusAddress); err == nil {
|
|
||||||
ignorePorts[port] = "prometheus"
|
ignorePorts[port] = "prometheus"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if port, err := extractPort(debugAddress); err == nil {
|
||||||
|
ignorePorts[port] = "debug"
|
||||||
|
}
|
||||||
|
|
||||||
// exchangeToken returns a session token.
|
// exchangeToken returns a session token.
|
||||||
// This is abstracted to allow for the same looping condition
|
// This is abstracted to allow for the same looping condition
|
||||||
// regardless of instance identity auth type.
|
// regardless of instance identity auth type.
|
||||||
|
@ -225,10 +227,6 @@ func (r *RootCmd) workspaceAgent() *clibase.Cmd {
|
||||||
|
|
||||||
debugSrvClose := ServeHandler(ctx, logger, agnt.HTTPDebug(), debugAddress, "debug")
|
debugSrvClose := ServeHandler(ctx, logger, agnt.HTTPDebug(), debugAddress, "debug")
|
||||||
defer debugSrvClose()
|
defer debugSrvClose()
|
||||||
// Do a best effort here. If this fails, it's not a big deal.
|
|
||||||
if port, err := urlPort(debugAddress); err == nil {
|
|
||||||
ignorePorts[port] = "debug"
|
|
||||||
}
|
|
||||||
|
|
||||||
<-ctx.Done()
|
<-ctx.Done()
|
||||||
return agnt.Close()
|
return agnt.Close()
|
||||||
|
|
|
@ -46,6 +46,12 @@ func Test_extractPort(t *testing.T) {
|
||||||
urlString: "6060",
|
urlString: "6060",
|
||||||
wantErr: true,
|
wantErr: true,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "127.0.0.1",
|
||||||
|
urlString: "127.0.0.1:2113",
|
||||||
|
want: 2113,
|
||||||
|
wantErr: false,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
tt := tt
|
tt := tt
|
||||||
|
|
Loading…
Reference in New Issue