Skip to content

Commit 21a77a3

Browse files
committed
Merge branch 'feat-proxy-config' of https://github.com/canonical/aproxy into feat-proxy-config
2 parents 3f2bcc5 + ae7286e commit 21a77a3

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

aproxy.go

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -214,8 +214,8 @@ func main() {
214214
log.Fatal(err)
215215
}
216216
listenAddr := *listenFlag
217-
ctx := context.Background()
218-
signal.NotifyContext(ctx, os.Interrupt)
217+
ctx, stop := signal.NotifyContext(context.Background(), os.Interrupt)
218+
defer stop()
219219
listenConfig := new(net.ListenConfig)
220220
listener, err := listenConfig.Listen(ctx, "tcp", listenAddr)
221221
if err != nil {
@@ -232,12 +232,16 @@ func main() {
232232
} else {
233233
logger.InfoContext(ctx, "start passthrough HTTPS connection")
234234
}
235-
for {
236-
conn, err := listener.Accept()
237-
if err != nil {
238-
logger.ErrorContext(ctx, "failed to accept connection", "error", err)
239-
continue
235+
go func() {
236+
for {
237+
conn, err := listener.Accept()
238+
if err != nil {
239+
logger.ErrorContext(ctx, "failed to accept connection", "error", err)
240+
continue
241+
}
242+
go HandleConn(conn, proxy)
240243
}
241-
go HandleConn(ctx, conn.(*net.TCPConn), forwarder)
242-
}
244+
}()
245+
<-ctx.Done()
246+
stop()
243247
}

0 commit comments

Comments
 (0)