Skip to content

Commit

Permalink
Added cause to context, moved logging of cause and added exit code
Browse files Browse the repository at this point in the history
  • Loading branch information
adrianrudnik committed Oct 4, 2024
1 parent eb57c8f commit f3dce8a
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func main() {
updater := newUpdater()
updater.StartWorker()

ctx, cancel := context.WithCancel(context.Background())
ctx, cancel := context.WithCancelCause(context.Background())

ipv6LocalAddress := os.Getenv("DEVICE_LOCAL_ADDRESS_IPV6")

Expand All @@ -51,7 +51,8 @@ func main() {
// Wait for either the context to finish or the shutdown signal
select {
case <-ctx.Done():
break
slog.Error("Context error", logging.ErrorAttr(context.Cause(ctx)))
os.Exit(1)
case <-shutdown:
break
}
Expand Down Expand Up @@ -143,7 +144,7 @@ func newUpdater() *cloudflare.Updater {
return u
}

func startPushServer(out chan<- *net.IP, localIp *net.IP, cancel context.CancelFunc) {
func startPushServer(out chan<- *net.IP, localIp *net.IP, cancel context.CancelCauseFunc) {
bind := os.Getenv("DYNDNS_SERVER_BIND")

if bind == "" {
Expand All @@ -164,8 +165,7 @@ func startPushServer(out chan<- *net.IP, localIp *net.IP, cancel context.CancelF

go func() {
err := s.ListenAndServe()
slog.Error("Server stopped", logging.ErrorAttr(err))
cancel()
cancel(err)
}()
}

Expand Down

0 comments on commit f3dce8a

Please sign in to comment.