Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix shutdown problems in ping application. #2141

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion cmd/ping/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,9 @@ func serveHTTP(ctlConf config, h healthcheck.Handler) func() {

go func() {
logger.Info("starting HTTP Server...")
logger.WithError(srv.ListenAndServe()).Fatal("could not start HTTP server")
if err := srv.ListenAndServe(); err != http.ErrServerClosed {
logger.WithError(err).Fatal("could not start HTTP server")
s-shin marked this conversation as resolved.
Show resolved Hide resolved
}
}()

return func() {
Expand All @@ -101,6 +103,7 @@ func serveHTTP(ctlConf config, h healthcheck.Handler) func() {
if err := srv.Shutdown(ctx); err != nil {
logger.WithError(err).Fatal("could not shut down HTTP server")
}
logger.Info("HTTP server was gracefully shut down")
}
}

Expand Down
4 changes: 4 additions & 0 deletions cmd/ping/udp.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"context"
"math"
"net"
"os"
"sync"
"time"

Expand Down Expand Up @@ -111,6 +112,9 @@ func (u *udpServer) readWriteLoop(ctx context.Context) {
b := make([]byte, 1024)
_, sender, err := u.conn.ReadFrom(b)
if err != nil {
if ctx.Err() != nil && err == os.ErrClosed {
return
}
u.logger.WithError(err).Error("error reading udp packet")
continue
}
Expand Down