Skip to content

Commit

Permalink
Fix shutdown behaviour (#10)
Browse files Browse the repository at this point in the history
* Fix shutdown behaviour

* Remove confusion log line
  • Loading branch information
pcallewaert authored Mar 22, 2024
1 parent addac74 commit 9deb7ca
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions aproxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -377,8 +377,8 @@ func main() {
listenFlag := flag.String("listen", ":8443", "the address and port on which the server will listen")
flag.Parse()
listenAddr := *listenFlag
ctx := context.Background()
signal.NotifyContext(ctx, os.Interrupt)
ctx, stop := signal.NotifyContext(context.Background(), os.Interrupt)
defer stop()
listenConfig := new(net.ListenConfig)
listener, err := listenConfig.Listen(ctx, "tcp", listenAddr)
if err != nil {
Expand All @@ -390,12 +390,16 @@ func main() {
log.Fatalf("no upstearm proxy specified")
}
slog.Info(fmt.Sprintf("start forwarding to proxy %s", proxy))
for {
conn, err := listener.Accept()
if err != nil {
slog.Error("failed to accept connection", "error", err)
continue
go func() {
for {
conn, err := listener.Accept()
if err != nil {
slog.Error("failed to accept connection", "error", err)
continue
}
go HandleConn(conn, proxy)
}
go HandleConn(conn, proxy)
}
}()
<-ctx.Done()
stop()
}

0 comments on commit 9deb7ca

Please sign in to comment.