Skip to content

Commit d61fd01

Browse files
committed
add context to the Proxy struct
1 parent 6b88f9c commit d61fd01

File tree

5 files changed

+9
-7
lines changed

5 files changed

+9
-7
lines changed

packages/client-proxy/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ func run() int {
275275
proxyRunLogger := logger.With(zap.Int("proxy_port", proxyPort))
276276
proxyRunLogger.Info("Http proxy starting")
277277

278-
err := trafficProxy.ListenAndServe()
278+
err := trafficProxy.ListenAndServe(ctx)
279279
// Add different handling for the error
280280
switch {
281281
case errors.Is(err, http.ErrServerClosed):

packages/orchestrator/cmd/build-template/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ func buildTemplate(
8787
logger.Fatal("failed to create sandbox proxy", zap.Error(err))
8888
}
8989
go func() {
90-
err := sandboxProxy.Start()
90+
err := sandboxProxy.Start(parentCtx)
9191
if err != nil && !errors.Is(err, http.ErrServerClosed) {
9292
logger.Error("failed to start sandbox proxy", zap.Error(err))
9393
}

packages/orchestrator/internal/proxy/proxy.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,8 @@ func NewSandboxProxy(meterProvider metric.MeterProvider, port uint, sandboxes *s
101101
return &SandboxProxy{proxy}, nil
102102
}
103103

104-
func (p *SandboxProxy) Start() error {
105-
return p.proxy.ListenAndServe()
104+
func (p *SandboxProxy) Start(ctx context.Context) error {
105+
return p.proxy.ListenAndServe(ctx)
106106
}
107107

108108
func (p *SandboxProxy) Close(ctx context.Context) error {

packages/orchestrator/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,7 @@ func run(port, proxyPort, hyperloopPort uint) (success bool) {
439439

440440
g.Go(func() error {
441441
zap.L().Info("Starting session proxy")
442-
proxyErr := sandboxProxy.Start()
442+
proxyErr := sandboxProxy.Start(ctx)
443443
if proxyErr != nil && !errors.Is(proxyErr, http.ErrServerClosed) {
444444
proxyErr = fmt.Errorf("proxy server: %w", proxyErr)
445445
zap.L().Error("error starting proxy server", zap.Error(proxyErr))

packages/shared/pkg/proxy/proxy.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package proxy
22

33
import (
4+
"context"
45
"fmt"
56
"net"
67
"net/http"
@@ -67,8 +68,9 @@ func (p *Proxy) RemoveFromPool(connectionKey string) {
6768
p.pool.Close(connectionKey)
6869
}
6970

70-
func (p *Proxy) ListenAndServe() error {
71-
l, err := net.Listen("tcp", p.Addr)
71+
func (p *Proxy) ListenAndServe(ctx context.Context) error {
72+
var lisCfg net.ListenConfig
73+
l, err := lisCfg.Listen(ctx, "tcp", p.Addr)
7274
if err != nil {
7375
return err
7476
}

0 commit comments

Comments
 (0)