Skip to content

Commit

Permalink
fix: fix logging an signal handling (#339)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexec committed Sep 17, 2021
1 parent ae8ad3f commit cc7706d
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 2,112 deletions.
1,048 changes: 0 additions & 1,048 deletions examples/git/go.sum

This file was deleted.

3 changes: 2 additions & 1 deletion kill/kill.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"log"
"os"
"strconv"
"syscall"
Expand All @@ -21,7 +22,7 @@ func mainE(pid int) error {
if err != nil {
return err
}
println("signaling pid with SIGTERM", "pid", pid)
log.Printf("signaling pid %d with SIGTERM\n", pid)
if err := p.Signal(syscall.SIGTERM); err != nil {
return err
}
Expand Down
3 changes: 2 additions & 1 deletion runner/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"net/http/pprof"
"os"
"os/signal"
"syscall"

"github.com/prometheus/client_golang/prometheus/promhttp"

Expand Down Expand Up @@ -47,7 +48,7 @@ func init() {
}

func main() {
ctx, stop := signal.NotifyContext(context.Background())
ctx, stop := signal.NotifyContext(context.Background(), syscall.SIGTERM)
defer stop()

start := func(f builtin.Process) error {
Expand Down
1,048 changes: 0 additions & 1,048 deletions runtimes/golang1-16/go.sum

This file was deleted.

9 changes: 9 additions & 0 deletions sdks/golang/crash.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package golang

import "log"

func HandleCrash() {
if r := recover(); r != nil {
log.Printf("recovered from crash: %v\n", r)
}
}
17 changes: 4 additions & 13 deletions sdks/golang/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@ import (
"net"
"net/http"
"os/signal"
"syscall"
)

//go:generate sh gen.sh

func Start(handler func(ctx context.Context, msg []byte) ([]byte, error)) {
ctx, stop := signal.NotifyContext(context.Background())
ctx, stop := signal.NotifyContext(context.Background(), syscall.SIGTERM)
defer stop()
if err := StartWithContext(ctx, handler); err != nil {
panic(err)
Expand Down Expand Up @@ -47,12 +48,7 @@ func StartWithContext(ctx context.Context, handler func(ctx context.Context, msg
// https://medium.com/honestbee-tw-engineer/gracefully-shutdown-in-go-http-server-5f5e6b83da5a
httpServer := &http.Server{Addr: ":8080"}
go func() {
defer func() {
r := recover()
if r != nil {
println(r)
}
}()
defer HandleCrash()
if err := httpServer.ListenAndServe(); err != nil && err != http.ErrServerClosed {
panic(err)
}
Expand All @@ -64,12 +60,7 @@ func StartWithContext(ctx context.Context, handler func(ctx context.Context, msg
}
defer func() { _ = listener.Close() }()
go func() {
defer func() {
r := recover()
if r != nil {
println(r)
}
}()
defer HandleCrash()
if err := udsServer.Serve(listener); err != nil && err != http.ErrServerClosed {
panic(err)
}
Expand Down
1 change: 1 addition & 0 deletions test/db-e2e/db_source_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ func TestDBSource(t *testing.T) {
},
})

WaitForPipeline()
WaitForPod()

defer StartPortForward("db-source-insert-0")()
Expand Down
1 change: 0 additions & 1 deletion test/metric.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ func ExpectMetric(name string, matcher matcher, opts ...interface{}) {
for {
select {
case <-ctx.Done():
println(getMetrics(ctx, port))
panic(fmt.Errorf("failed to wait for metric named %q to be %s: %w", name, matcher, ctx.Err()))
default:
found := false
Expand Down

0 comments on commit cc7706d

Please sign in to comment.