]> go.fuhry.dev Git - runtime.git/commitdiff
bulk replace all signal.NotifyContext with utils/context.Interruptible()
authorDan Fuhry <dan@fuhry.com>
Fri, 14 Nov 2025 17:29:15 +0000 (12:29 -0500)
committerDan Fuhry <dan@fuhry.com>
Fri, 14 Nov 2025 17:35:20 +0000 (12:35 -0500)
48 files changed:
attestation/rpc_client/BUILD.bazel
attestation/rpc_client/main.go
attestation/rpc_server/BUILD.bazel
attestation/rpc_server/main.go
automation/bryston_ctl/client/BUILD.bazel
automation/bryston_ctl/client/main.go
automation/bryston_ctl/server/BUILD.bazel
automation/bryston_ctl/server/main.go
cmd/apcups_exporter/BUILD.bazel
cmd/apcups_exporter/main.go
cmd/echo_client/BUILD.bazel
cmd/echo_client/main.go
cmd/echo_server/BUILD.bazel
cmd/echo_server/main.go
cmd/ephs_client/BUILD.bazel
cmd/ephs_client/main.go
cmd/ephs_server/BUILD.bazel
cmd/ephs_server/main.go
cmd/grpc_health_probe/BUILD.bazel
cmd/grpc_health_probe/main.go
cmd/http_proxy/BUILD.bazel
cmd/http_proxy/main.go
cmd/machines_event_monitor/BUILD.bazel
cmd/machines_event_monitor/main.go
cmd/metricbus_server/BUILD.bazel
cmd/metricbus_server/main.go
cmd/mtls_exporter/BUILD.bazel
cmd/mtls_exporter/main.go
cmd/mtls_supervisor/BUILD.bazel
cmd/mtls_supervisor/main.go
cmd/prometheus_http_discovery/BUILD.bazel
cmd/prometheus_http_discovery/main.go
cmd/sase_ws_tcp_proxy/BUILD.bazel
cmd/sase_ws_tcp_proxy/main.go
cmd/sd_health_exporter/BUILD.bazel
cmd/sd_health_exporter/main.go
cmd/sd_publish/BUILD.bazel
cmd/sd_publish/main.go
cmd/sd_register/BUILD.bazel
cmd/sd_register/main.go
cmd/sd_watcher/BUILD.bazel
cmd/sd_watcher/main.go
metrics/metricbus/mbclient/example/BUILD.bazel
metrics/metricbus/mbclient/example/main.go
sd/BUILD.bazel
sd/etcd_factory.go
thirdparty/registry/BUILD.bazel
thirdparty/registry/main.go

index 6ba0d80cc35118475a991831533cd7186c76f6bc..71bcdade512f52daccac9d9b920bd841ecb2b0f9 100644 (file)
@@ -10,6 +10,7 @@ go_library(
         "//grpc",
         "//mtls",
         "//proto/service/attest",
+        "//utils/context",
     ],
 )
 
index aad59859a96511e82ddf975df29b5b7805aff155..d82dd98c60c68bf8f09b6e6857b2b3dad4ea5392 100644 (file)
@@ -1,20 +1,19 @@
 package main
 
 import (
-       "context"
        "flag"
        "fmt"
-       "os/signal"
-       "syscall"
 
        "go.fuhry.dev/runtime/attestation/internal/attestation"
        "go.fuhry.dev/runtime/grpc"
        "go.fuhry.dev/runtime/mtls"
        attest_pb "go.fuhry.dev/runtime/proto/service/attest"
+       "go.fuhry.dev/runtime/utils/context"
 )
 
 func main() {
-       ctx, _ := signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM)
+       ctx, cancel := context.Interruptible()
+       defer cancel()
 
        flag.Parse()
 
index 4b6aabfdcf0b0e2115df91dbe1a625b530aa48cc..4043c16c5a09708cf5d532b61fec29f9ffb49f3a 100644 (file)
@@ -10,6 +10,7 @@ go_library(
         "//grpc",
         "//mtls",
         "//proto/service/attest",
+        "//utils/context",
         "@org_golang_google_grpc//:grpc",
     ],
 )
index 5945a5a7c9e619f4f385fdbcf8f43c41f215061b..e62da24ab41aa9f7900b151228a8477518bf1ec4 100644 (file)
@@ -1,15 +1,13 @@
 package main
 
 import (
-       "context"
        "flag"
-       "os/signal"
-       "syscall"
 
        "go.fuhry.dev/runtime/attestation/internal/attestation"
        "go.fuhry.dev/runtime/grpc"
        "go.fuhry.dev/runtime/mtls"
        attest_pb "go.fuhry.dev/runtime/proto/service/attest"
+       "go.fuhry.dev/runtime/utils/context"
 
        google_grpc "google.golang.org/grpc"
 )
@@ -25,7 +23,8 @@ func main() {
                panic(err)
        }
 
-       ctx, _ := signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM)
+       ctx, cancel := context.Interruptible()
+       defer cancel()
 
        err = s.PublishAndServe(ctx, func(s *google_grpc.Server) {
                attest_pb.RegisterAttestServer(s, attestation.NewAttestationServer())
index 29d2dc479afa59c6fd7d4bf3599f083ca4c50267..be8018a4b49f72c803ff5c8e3fe6b31c21dfb34b 100644 (file)
@@ -10,6 +10,7 @@ go_library(
         "//grpc",
         "//mtls",
         "//proto/service/bryston_ctl",
+        "//utils/context",
         "//utils/log",
     ],
 )
index 723d8f699b26f5a4359527c8c472038fd1c64dfa..5695ac0775f39a158e3dc7f9a80d7e8fe373fca4 100644 (file)
@@ -1,20 +1,19 @@
 package main
 
 import (
-       "context"
        "flag"
-       "os/signal"
-       "syscall"
 
        "go.fuhry.dev/runtime/automation/bryston_ctl"
        "go.fuhry.dev/runtime/grpc"
        "go.fuhry.dev/runtime/mtls"
        bryston_ctl_pb "go.fuhry.dev/runtime/proto/service/bryston_ctl"
+       "go.fuhry.dev/runtime/utils/context"
        "go.fuhry.dev/runtime/utils/log"
 )
 
 func main() {
-       ctx, _ := signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM)
+       ctx, cancel := context.Interruptible()
+       defer cancel()
 
        model, modelFF := bryston_ctl.NewBrystonModelFlag()
        flag.Func("model", "Bryston device model to control", modelFF)
index a360b3354e2624746ea4c56993998adc73d7c5c4..f176641da609c935946f5c5b62173536d9139ea9 100644 (file)
@@ -10,6 +10,7 @@ go_library(
         "//grpc",
         "//mtls",
         "//proto/service/bryston_ctl",
+        "//utils/context",
         "//utils/log",
         "@org_golang_google_grpc//:grpc",
     ],
index d93fe73c2d88a562e7c3aed956d40c68604ec0fa..6099f5fb74a5bbe107613cdea7d6207b514a2be1 100644 (file)
@@ -1,10 +1,7 @@
 package main
 
 import (
-       "context"
        "flag"
-       "os/signal"
-       "syscall"
 
        google_grpc "google.golang.org/grpc"
 
@@ -12,6 +9,7 @@ import (
        "go.fuhry.dev/runtime/grpc"
        "go.fuhry.dev/runtime/mtls"
        bryston_ctl_pb "go.fuhry.dev/runtime/proto/service/bryston_ctl"
+       "go.fuhry.dev/runtime/utils/context"
        "go.fuhry.dev/runtime/utils/log"
 )
 
@@ -26,7 +24,8 @@ func main() {
                log.Panic(err)
        }
 
-       ctx, _ := signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM)
+       ctx, cancel := context.Interruptible()
+       defer cancel()
 
        ctl, err := bryston_ctl.NewController()
        if err != nil {
index fc8d96043aa656b3e595919efb97ef4c27fd866a..535738011d34c4287b6cfff76331eb697be9f4bd 100644 (file)
@@ -7,6 +7,7 @@ go_library(
     visibility = ["//visibility:private"],
     deps = [
         "//metrics/metricbus/mbclient",
+        "//utils/context",
         "//utils/log",
         "@com_github_coreos_go_systemd//daemon",
         "@com_github_mdlayher_apcupsd//:apcupsd",
index 54e7b715b69d4c778800749335959f9400b1f5f7..e7d69ba1115ef0b5420f68c26b9e08120fc1331f 100644 (file)
@@ -1,17 +1,15 @@
 package main
 
 import (
-       "context"
        "flag"
-       "os/signal"
        "sync"
-       "syscall"
        "time"
 
        "github.com/coreos/go-systemd/daemon"
        "github.com/mdlayher/apcupsd"
 
        "go.fuhry.dev/runtime/metrics/metricbus/mbclient"
+       "go.fuhry.dev/runtime/utils/context"
        "go.fuhry.dev/runtime/utils/log"
 )
 
@@ -31,7 +29,8 @@ func main() {
        flag.StringVar(&apcUpsdAddr, "apcupsd-addr", apcUpsdAddr, "address at which apcupsd can be contacted")
        flag.IntVar(&nominalPower, "apcupsd-nominal-power", nominalPower, "max power output in W for the UPS - only used if apcupsd does not specify NOMPOWER")
 
-       ctx, _ := signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM)
+       ctx, cancel := context.Interruptible()
+       defer cancel()
        flag.Parse()
 
        svc := mbclient.NewService(ctx)
index 6f28a7beac49b4c8ca3e5a0976255505f4e83b9f..7e06801ac2d9e7837d7202b07f0c58f30c32f58f 100644 (file)
@@ -9,6 +9,7 @@ go_library(
         "//grpc",
         "//mtls",
         "//proto/service/echo",
+        "//utils/context",
         "//utils/log",
     ],
 )
index 98063ec935fd6620bdd2fa3034add041fd0c07d8..76f7cf1f8c7a1a3a08c624d37851a59780f09fb3 100644 (file)
@@ -1,19 +1,18 @@
 package main
 
 import (
-       "context"
        "flag"
-       "os/signal"
-       "syscall"
 
        "go.fuhry.dev/runtime/grpc"
        "go.fuhry.dev/runtime/mtls"
        echo_pb "go.fuhry.dev/runtime/proto/service/echo"
+       "go.fuhry.dev/runtime/utils/context"
        "go.fuhry.dev/runtime/utils/log"
 )
 
 func main() {
-       ctx, _ := signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM)
+       ctx, cancel := context.Interruptible()
+       defer cancel()
 
        flag.Parse()
        logger := log.Default().WithPrefix("EchoClient")
index db44ca8b4e9f182f06cb4e5b63b89cfe04e28185..206c25c9794b5795edc53bcf17fb1a10dea89986 100644 (file)
@@ -10,6 +10,7 @@ go_library(
         "//grpc",
         "//mtls",
         "//proto/service/echo",
+        "//utils/context",
         "@org_golang_google_grpc//:grpc",
     ],
 )
index a4b30fd84fc44c12dcfe8c855584b0306fc40f15..d7c634789afbb6114865f9de9243436dac49d617 100644 (file)
@@ -1,15 +1,13 @@
 package main
 
 import (
-       "context"
        "flag"
-       "os/signal"
-       "syscall"
 
        "go.fuhry.dev/runtime/echo"
        "go.fuhry.dev/runtime/grpc"
        "go.fuhry.dev/runtime/mtls"
        echo_pb "go.fuhry.dev/runtime/proto/service/echo"
+       "go.fuhry.dev/runtime/utils/context"
 
        google_grpc "google.golang.org/grpc"
 )
@@ -25,7 +23,8 @@ func main() {
                panic(err)
        }
 
-       ctx, _ := signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM)
+       ctx, cancel := context.Interruptible()
+       defer cancel()
 
        err = s.PublishAndServe(ctx, func(s *google_grpc.Server) {
                echo_pb.RegisterEchoServer(s, echo.NewEchoServer())
index e0a14f51578bfd074cb0c88f7bd22b5a4819cc33..ee40c3280ae021461d19ed72e5d9d714c25778f4 100644 (file)
@@ -8,6 +8,7 @@ go_library(
     deps = [
         "//constants",
         "//ephs",
+        "//utils/context",
         "//utils/log",
         "@com_github_urfave_cli_v3//:cli",
     ],
index f15ca2422a0e0c650ebc4ead418ecac9d4420ec0..b0b113ddc6993053b67d6ad80b8782e8d78e9b46 100644 (file)
@@ -1,21 +1,19 @@
 package main
 
 import (
-       "context"
        "errors"
        "flag"
        "fmt"
        "io"
        "os"
-       "os/signal"
        "path"
        "strings"
-       "syscall"
 
        "github.com/urfave/cli/v3"
 
        "go.fuhry.dev/runtime/constants"
        "go.fuhry.dev/runtime/ephs"
+       "go.fuhry.dev/runtime/utils/context"
        "go.fuhry.dev/runtime/utils/log"
 )
 
@@ -157,7 +155,7 @@ func cmdMkdir(ctx context.Context, cmd *cli.Command) error {
 }
 
 func main() {
-       ctx, cancel := signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM)
+       ctx, cancel := context.Interruptible()
        defer cancel()
 
        flag.Parse()
index f983df06ec86d4b38d722c303b0ab16a8b2f64e2..3d77a80f36b1c156d17e2d49f2ce9c5317b3dc31 100644 (file)
@@ -10,6 +10,7 @@ go_library(
         "//grpc",
         "//mtls",
         "//proto/service/ephs",
+        "//utils/context",
         "//utils/log",
         "@org_golang_google_grpc//:grpc",
     ],
index d0e24cfea9bc165797d7f03103df443a13101f35..2995fa3728dd415f765cf43896224779745f2c89 100644 (file)
@@ -1,15 +1,13 @@
 package main
 
 import (
-       "context"
        "flag"
-       "os/signal"
-       "syscall"
 
        "go.fuhry.dev/runtime/ephs/servicer"
        "go.fuhry.dev/runtime/grpc"
        "go.fuhry.dev/runtime/mtls"
        ephs_pb "go.fuhry.dev/runtime/proto/service/ephs"
+       "go.fuhry.dev/runtime/utils/context"
        "go.fuhry.dev/runtime/utils/log"
 
        google_grpc "google.golang.org/grpc"
@@ -46,7 +44,8 @@ func main() {
                log.Fatal(err)
        }
 
-       ctx, _ := signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM)
+       ctx, cancel := context.Interruptible()
+       defer cancel()
 
        err = s.PublishAndServe(ctx, func(s *google_grpc.Server) {
                ephs_pb.RegisterEphsServer(s, serv)
index cda6e8ead362995b1d873f5e3fc1ae9f4bb9e0bc..1d65ca1146f9241fd337ee9c8156013d5c712efb 100644 (file)
@@ -8,6 +8,7 @@ go_library(
     deps = [
         "//grpc",
         "//mtls",
+        "//utils/context",
         "//utils/log",
         "@org_golang_google_grpc//health/grpc_health_v1",
     ],
index a32adc9b710cf2d21b8534b820c5215f8c19638a..648a0ab9f549568ee33b4c33c771cd7fad036413 100644 (file)
@@ -1,17 +1,15 @@
 package main
 
 import (
-       "context"
        "flag"
        "net"
        "os"
-       "os/signal"
        "strconv"
-       "syscall"
        "time"
 
        "go.fuhry.dev/runtime/grpc"
        "go.fuhry.dev/runtime/mtls"
+       "go.fuhry.dev/runtime/utils/context"
        "go.fuhry.dev/runtime/utils/log"
 
        "google.golang.org/grpc/health/grpc_health_v1"
@@ -55,7 +53,7 @@ func main() {
                }
        }
 
-       ctx, cancel := signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM)
+       ctx, cancel := context.Interruptible()
        defer cancel()
        var deadline time.Time
 
index b296f298982cd39bfbb11f7a03e047d2959ef871..edf922b43c8983a7e05d5a4fc6d92562570d96a9 100644 (file)
@@ -9,6 +9,7 @@ go_library(
         "//config_watcher",
         "//ephs",
         "//http",
+        "//utils/context",
         "//utils/log",
         "@com_github_coreos_go_systemd//daemon",
         "@in_gopkg_yaml_v3//:yaml_v3",
index c0c6b90127b363932df927f4e791202e8c1f925b..fa7c0428af395085dc8700637b8baf762349e178 100644 (file)
@@ -1,10 +1,7 @@
 package main
 
 import (
-       "context"
        "flag"
-       "os/signal"
-       "syscall"
        "time"
 
        "github.com/coreos/go-systemd/daemon"
@@ -13,11 +10,12 @@ import (
        "go.fuhry.dev/runtime/config_watcher"
        "go.fuhry.dev/runtime/ephs"
        "go.fuhry.dev/runtime/http"
+       "go.fuhry.dev/runtime/utils/context"
        "go.fuhry.dev/runtime/utils/log"
 )
 
 func main() {
-       ctx, cancel := signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM)
+       ctx, cancel := context.Interruptible()
        defer cancel()
 
        ephs.DefaultClientContext = ctx
index 1e73bcfdd193aacdd436ba9888bb1eb60553a9c7..986d02c4d577bfa016be891a79f49d80f8075c79 100644 (file)
@@ -7,6 +7,7 @@ go_library(
     visibility = ["//visibility:private"],
     deps = [
         "//machines",
+        "//utils/context",
         "//utils/log",
     ],
 )
index c79325a3723ddb132fc99226fb072f7da742d44f..c1ce44286171bae8574c96c914c64fa5c228feac 100644 (file)
@@ -1,13 +1,11 @@
 package main
 
 import (
-       "context"
        "flag"
        "os"
-       "os/signal"
-       "syscall"
 
        "go.fuhry.dev/runtime/machines"
+       "go.fuhry.dev/runtime/utils/context"
        "go.fuhry.dev/runtime/utils/log"
 )
 
@@ -15,7 +13,8 @@ func main() {
        flag.Parse()
        logger := log.WithPrefix("main")
 
-       ctx, _ := signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM)
+       ctx, cancel := context.Interruptible()
+       defer cancel()
 
        client, err := machines.NewDefaultMachinesClient("host.attestation.client")
        if err != nil {
index 7a2dbc712b6a6f139c9149dcf1d21339ade6217f..46abb28f5472c2d3bc62c6f974df1f5d1939105d 100644 (file)
@@ -7,6 +7,7 @@ go_library(
     visibility = ["//visibility:private"],
     deps = [
         "//metrics/metricbus/mbserver",
+        "//utils/context",
         "//utils/log",
     ],
 )
index c48621c0a9e2fe96ca78b0bb01d13a19c1b1871d..3bc22793d66a3f93f8af0913f271c3bf576efd4b 100644 (file)
@@ -1,17 +1,16 @@
 package main
 
 import (
-       "context"
        "flag"
-       "os/signal"
-       "syscall"
 
        "go.fuhry.dev/runtime/metrics/metricbus/mbserver"
+       "go.fuhry.dev/runtime/utils/context"
        "go.fuhry.dev/runtime/utils/log"
 )
 
 func main() {
-       ctx, _ := signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM)
+       ctx, cancel := context.Interruptible()
+       defer cancel()
        serverCtx, cancel := context.WithCancel(context.Background())
 
        flag.Parse()
index 797409d5738320e28c4b20b8be0308551ac44d15..24d297886fefd2ac94532cdaee1395f240ff07a6 100644 (file)
@@ -7,6 +7,7 @@ go_library(
     visibility = ["//visibility:private"],
     deps = [
         "//metrics/mtls",
+        "//utils/context",
         "@com_github_coreos_go_systemd//daemon",
     ],
 )
index 636dbad1b19193929cd8355c70f2eefd8d844cb4..6c6abd25f4182173bcf7751c0105726243616fb5 100644 (file)
@@ -1,18 +1,17 @@
 package main
 
 import (
-       "context"
        "flag"
-       "os/signal"
-       "syscall"
        "time"
 
        "github.com/coreos/go-systemd/daemon"
        "go.fuhry.dev/runtime/metrics/mtls"
+       "go.fuhry.dev/runtime/utils/context"
 )
 
 func main() {
-       ctx, _ := signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM)
+       ctx, cancel := context.Interruptible()
+       defer cancel()
        flag.Parse()
 
        svc := mtls.NewMtlsMetricsService(ctx)
index 103280ffbd3b40e549b6f9652e142d454fdffe7b..4c16b5b59c2eed2f2ffb244f9e91b9d98b62cdf4 100644 (file)
@@ -10,6 +10,7 @@ go_library(
     visibility = ["//visibility:private"],
     deps = [
         "//mtls/fsnotify",
+        "//utils/context",
         "//utils/debounce",
         "//utils/hashset",
         "//utils/log",
index 6e0c213ecac879e5bbbde4fe21dce5d89b816731..fe36c94e247ac87638357e7298f54fc054fc5040 100644 (file)
@@ -2,7 +2,6 @@ package main
 
 import (
        "bytes"
-       "context"
        "crypto"
        "fmt"
        "io"
@@ -17,6 +16,7 @@ import (
        "time"
 
        "go.fuhry.dev/runtime/mtls/fsnotify"
+       "go.fuhry.dev/runtime/utils/context"
        "go.fuhry.dev/runtime/utils/debounce"
        "go.fuhry.dev/runtime/utils/hashset"
        "go.fuhry.dev/runtime/utils/log"
@@ -32,7 +32,7 @@ func main() {
                log.SetLevel(log.DEBUG)
        }
 
-       ctx, cancel := signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM)
+       ctx, cancel := context.Interruptible()
        logger := log.Default().WithPrefix("supervisor")
        defer cancel()
 
index 01c072d9bd72cfde6c6d583b5a0ec22e38fabcc9..a35c126934938b0683ba9f51c0a977a56de4cdbc 100644 (file)
@@ -9,6 +9,7 @@ go_library(
         "//constants",
         "//mtls",
         "//sd",
+        "//utils/context",
         "//utils/log",
         "@com_github_coreos_go_systemd//daemon",
     ],
index 7e6462a94e47fe081c2c51d75952c417828190e7..b286dfbfdb93d9fb759ca0b1d5646974b435ca44 100644 (file)
@@ -1,14 +1,11 @@
 package main
 
 import (
-       "context"
        "encoding/json"
        "flag"
        "fmt"
        "net/http"
-       "os/signal"
        "sync"
-       "syscall"
        "time"
 
        "github.com/coreos/go-systemd/daemon"
@@ -16,6 +13,7 @@ import (
        "go.fuhry.dev/runtime/constants"
        "go.fuhry.dev/runtime/mtls"
        "go.fuhry.dev/runtime/sd"
+       "go.fuhry.dev/runtime/utils/context"
        "go.fuhry.dev/runtime/utils/log"
 )
 
@@ -26,7 +24,8 @@ type endpoint struct {
 
 func main() {
        mtls.SetDefaultIdentity("node-exporter")
-       ctx, _ := signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM)
+       ctx, cancel := context.Interruptible()
+       defer cancel()
        serverCtx, cancel := context.WithCancel(context.Background())
        defer cancel()
 
index aae5a060afc94f72c8c302b0a58dfcc3a8c47198..2cfd80c572634aef0a22e07d2790f6f655bafc5e 100644 (file)
@@ -11,6 +11,7 @@ go_library(
         "//rand",
         "//sase",
         "//sd",
+        "//utils/context",
     ],
 )
 
index 89e50578f7b7e4f5c0ffd1cbad7ea6c09b9282c9..51d7d2c5ace203ff1c7298a00725543829f2319a 100644 (file)
@@ -1,13 +1,10 @@
 package main
 
 import (
-       "context"
        "flag"
        "fmt"
-       "os/signal"
        "strconv"
        "strings"
-       "syscall"
        "time"
 
        "go.fuhry.dev/runtime/constants"
@@ -15,6 +12,7 @@ import (
        "go.fuhry.dev/runtime/rand"
        "go.fuhry.dev/runtime/sase"
        "go.fuhry.dev/runtime/sd"
+       "go.fuhry.dev/runtime/utils/context"
 )
 
 func main() {
@@ -28,7 +26,8 @@ func main() {
 
        flag.Parse()
 
-       ctx, _ := signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM)
+       ctx, cancel := context.Interruptible()
+       defer cancel()
 
        listenPort, err := strconv.Atoi(addr[strings.LastIndex(addr, ":")+1:])
        if err != nil {
index 061f94fc35ea827324bafcca707c8ffbf2666730..7030a73a6e7179d9b8833dc4e1f11f0340eab832 100644 (file)
@@ -8,6 +8,7 @@ go_library(
     deps = [
         "//mtls",
         "//sd",
+        "//utils/context",
         "@io_etcd_go_etcd_client_v3//:client",
     ],
 )
index bd58ab12909577fdc4ef7981bbec6d13c90d5786..26db85235ca30ad5f6e9a3d016c36d942e1aeb20 100644 (file)
@@ -1,21 +1,19 @@
 package main
 
 import (
-       "context"
        "crypto/tls"
        "encoding/json"
        "flag"
        "fmt"
        "net"
        "net/http"
-       "os/signal"
        "strings"
        "sync"
-       "syscall"
 
        etcd_client "go.etcd.io/etcd/client/v3"
        "go.fuhry.dev/runtime/mtls"
        "go.fuhry.dev/runtime/sd"
+       "go.fuhry.dev/runtime/utils/context"
 )
 
 func main() {
@@ -32,7 +30,8 @@ func main() {
        keys := make(map[string][]byte, 0)
        keysLock := &sync.RWMutex{}
 
-       ctx, _ := signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM)
+       ctx, cancel := context.Interruptible()
+       defer cancel()
 
        handler := http.NewServeMux()
        server := &http.Server{
index ca300a045d08994040f9bde8ea5d26cba586b4c0..4ac44c67c3e1b3495dcf80831941507e712e6309 100644 (file)
@@ -8,6 +8,7 @@ go_library(
     deps = [
         "//constants",
         "//sd",
+        "//utils/context",
         "//utils/hostname",
     ],
 )
index 76813c94b3e3453a94b621f3e3ad335a4681d78e..10e4d3058ca8282799a1bcdaf405a53bbf5b1dec 100644 (file)
@@ -1,19 +1,18 @@
 package main
 
 import (
-       "context"
        "flag"
-       "os/signal"
        "strings"
-       "syscall"
 
        "go.fuhry.dev/runtime/constants"
        "go.fuhry.dev/runtime/sd"
+       "go.fuhry.dev/runtime/utils/context"
        "go.fuhry.dev/runtime/utils/hostname"
 )
 
 func main() {
-       ctx, _ := signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM)
+       ctx, cancel := context.Interruptible()
+       defer cancel()
 
        svc := &sd.SDPublisher{}
        var port uint
index e69af4ee3ac38616c16101acc86c4b7bacadc104..63e4a58533384cfc15261729d270a7b75a2b9432 100644 (file)
@@ -8,6 +8,7 @@ go_library(
     deps = [
         "//constants",
         "//sd",
+        "//utils/context",
         "//utils/hostname",
         "//utils/log",
     ],
index 2f85d097c30161d39d3639d9f092e2e694cd1e22..3db2a501d04b2ba47e9d592cb2a24337ce31439c 100644 (file)
@@ -1,18 +1,16 @@
 package main
 
 import (
-       "context"
        "flag"
        "fmt"
        "os"
-       "os/signal"
        "path"
        "strings"
        "sync"
-       "syscall"
 
        "go.fuhry.dev/runtime/constants"
        "go.fuhry.dev/runtime/sd"
+       "go.fuhry.dev/runtime/utils/context"
        "go.fuhry.dev/runtime/utils/hostname"
        "go.fuhry.dev/runtime/utils/log"
 )
@@ -57,7 +55,8 @@ func main() {
        flag.StringVar(&region, "region", defaultRegion, "regional shard to publish under; separate multiple shards with commas")
        flag.Parse()
 
-       ctx, _ := signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM)
+       ctx, cancel := context.Interruptible()
+       defer cancel()
 
        if len(confs) < 1 {
                flag.Usage()
index a22f229ecde1d5fff44a7b0ce6f4c0378daf39a8..de324cd60238aab3952f28826aeed5c63f42c9cc 100644 (file)
@@ -8,6 +8,7 @@ go_library(
     deps = [
         "//constants",
         "//sd",
+        "//utils/context",
     ],
 )
 
index a88a7930763243a6a6408260f580ad50a8a79ce4..63d814d427d3d4389131639bd9bedd6fb5678920 100644 (file)
@@ -1,16 +1,14 @@
 package main
 
 import (
-       "context"
        "flag"
        "fmt"
        "os"
-       "os/signal"
-       "syscall"
        "time"
 
        "go.fuhry.dev/runtime/constants"
        "go.fuhry.dev/runtime/sd"
+       "go.fuhry.dev/runtime/utils/context"
 )
 
 func main() {
@@ -37,7 +35,8 @@ func main() {
                panic(err)
        }
 
-       ctx, _ := signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM)
+       ctx, cancel := context.Interruptible()
+       defer cancel()
 
        watcher := &sd.SDWatcher{
                Domain:   domain,
index 0220762ad8b335d23086a38b6aa5c9f65358ad3b..b6ec8169fb1e02eda89ec39c385a42ae06e4eb2f 100644 (file)
@@ -5,7 +5,10 @@ go_library(
     srcs = ["main.go"],
     importpath = "go.fuhry.dev/runtime/metrics/metricbus/mbclient/example",
     visibility = ["//visibility:private"],
-    deps = ["//metrics/metricbus/mbclient"],
+    deps = [
+        "//metrics/metricbus/mbclient",
+        "//utils/context",
+    ],
 )
 
 go_binary(
index 9f9a72f8e6c94642f9d9af81622f5ea8903b7f2c..411be18bc5e7920b4b7b3ecccb570da8fe8265c6 100644 (file)
@@ -1,18 +1,17 @@
 package main
 
 import (
-       "context"
        "flag"
        "math/rand"
-       "os/signal"
-       "syscall"
        "time"
 
        "go.fuhry.dev/runtime/metrics/metricbus/mbclient"
+       "go.fuhry.dev/runtime/utils/context"
 )
 
 func main() {
-       ctx, _ := signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM)
+       ctx, cancel := context.Interruptible()
+       defer cancel()
        flag.Parse()
 
        svc := mbclient.NewServiceWithDiscriminator(ctx, "merr")
index 9f1257b35eb552e7be80a4909eb3beb8058e39c5..9c2fa502482c0c912cdf0ecb54d333dc9ab0acca 100644 (file)
@@ -19,6 +19,7 @@ go_library(
         "//mtls/certutil",
         "//net/dns",
         "//utils",
+        "//utils/context",
         "//utils/hostname",
         "//utils/log",
         "@com_github_go_ldap_ldap_v3//:ldap",
index d9a9524d1bac0735369c9f5edc3947bc84a4ce6b..11c183ee8278507cf4272c4a3c2d62c623f34957 100644 (file)
@@ -1,7 +1,7 @@
 package sd
 
 import (
-       "context"
+       "errors"
        "flag"
        "fmt"
        "sync"
@@ -11,6 +11,7 @@ import (
        "go.etcd.io/etcd/client/pkg/v3/srv"
        etcd_client "go.etcd.io/etcd/client/v3"
        "go.fuhry.dev/runtime/mtls"
+       "go.fuhry.dev/runtime/utils/context"
        "go.fuhry.dev/runtime/utils/hostname"
        "go.fuhry.dev/runtime/utils/log"
 )
@@ -39,6 +40,9 @@ func NewDefaultEtcdClient() (*etcd_client.Client, error) {
                        }
 
                        clientSingleton, err = NewEtcdClient(id, etcdDiscoveryDomain)
+                       if errors.Is(err, context.Canceled) || errors.Is(err, context.DeadlineExceeded) {
+                               return nil, err
+                       }
                        if err == nil {
                                break
                        }
@@ -63,7 +67,9 @@ func NewEtcdClient(id mtls.Identity, domain string) (*etcd_client.Client, error)
 func NewEtcdClientWithDeadline(id mtls.Identity, domain string, deadline time.Time) (*etcd_client.Client, error) {
        var client *etcd_client.Client
 
-       tlsConfig, err := id.TlsConfig(context.Background())
+       ctx, _ := context.Interruptible()
+
+       tlsConfig, err := id.TlsConfig(ctx)
        if err != nil {
                return nil, fmt.Errorf("failed to setup client TLS configuration: %v", err)
        }
@@ -82,6 +88,7 @@ func NewEtcdClientWithDeadline(id mtls.Identity, domain string, deadline time.Ti
        dialTimeout := time.Until(deadline)
 
        clientConfig := etcd_client.Config{
+               Context:     ctx,
                DialTimeout: dialTimeout,
                Endpoints:   clients.Endpoints,
                TLS:         tlsConfig,
index f91e4d04a28ffffdb3105949e92dce6d991e0740..44f73228d7b658f78e6c6016bf19b6d8f3a5dc11 100644 (file)
@@ -11,6 +11,7 @@ go_library(
         "//metrics/metricbus/mbclient",
         "//mtls",
         "//sd",
+        "//utils/context",
         "//utils/log",
         "@com_github_distribution_distribution_v3//configuration",
         "@com_github_distribution_distribution_v3//registry/auth/htpasswd",
index 30d026d5f0fb74e8a8bbed5efaa8f08719082587..6ad7a1f39bc0e9392dfc94c162cddf7ee70e3dc6 100644 (file)
@@ -1,7 +1,6 @@
 package main
 
 import (
-       "context"
        "crypto/tls"
        "flag"
        "fmt"
@@ -9,9 +8,7 @@ import (
        "net/http"
        _ "net/http/pprof"
        "os"
-       "os/signal"
        "strconv"
-       "syscall"
 
        "github.com/distribution/distribution/v3/configuration"
        _ "github.com/distribution/distribution/v3/registry/auth/htpasswd"
@@ -28,6 +25,7 @@ import (
        "go.fuhry.dev/runtime/metrics/metricbus/mbclient"
        "go.fuhry.dev/runtime/mtls"
        "go.fuhry.dev/runtime/sd"
+       "go.fuhry.dev/runtime/utils/context"
        "go.fuhry.dev/runtime/utils/log"
 )
 
@@ -52,7 +50,8 @@ func main() {
        flag.StringVar(&configPath, "registry.config-path", "config.yml", "path to configuration file")
        flag.Parse()
        logger = log.WithPrefix("registry")
-       ctx, _ := signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM)
+       ctx, cancel := context.Interruptible()
+       defer cancel()
 
        metricsService := mbclient.NewService(ctx)
        defer metricsService.FlushAndWait()