From bac7122d7b8bb483939ab54fa8f71e30be0dc4d6 Mon Sep 17 00:00:00 2001 From: Ivan Kozlovic Date: Fri, 30 Oct 2020 18:43:59 -0600 Subject: [PATCH] [FIXED] Fatal error on startup not logged to log file Resolves #1118 Signed-off-by: Ivan Kozlovic --- .travis.yml | 1 - README.md | 4 ++-- server/server.go | 7 +++++-- server/server_run_test.go | 5 +++-- 4 files changed, 10 insertions(+), 7 deletions(-) diff --git a/.travis.yml b/.travis.yml index def80d5f..dd7a02d2 100644 --- a/.travis.yml +++ b/.travis.yml @@ -14,7 +14,6 @@ env: go_import_path: github.com/nats-io/nats-streaming-server install: - go get -t ./... -- go get github.com/nats-io/nats-server - if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then go get -u honnef.co/go/tools/cmd/staticcheck; go get -u github.com/client9/misspell/cmd/misspell; diff --git a/README.md b/README.md index cd44332f..f522e59d 100644 --- a/README.md +++ b/README.md @@ -38,8 +38,8 @@ under the Apache Version 2.0 license found in the LICENSE file. [License-Url]: https://www.apache.org/licenses/LICENSE-2.0 [License-Image]: https://img.shields.io/badge/License-Apache2-blue.svg -[Build-Status-Url]: http://travis-ci.org/nats-io/nats-streaming-server -[Build-Status-Image]: https://travis-ci.org/nats-io/nats-streaming-server.svg?branch=master +[Build-Status-Url]: https://travis-ci.com/github/nats-io/nats-streaming-server +[Build-Status-Image]: https://travis-ci.com/nats-io/nats-streaming-server.svg?branch=master [Coverage-Url]: https://coveralls.io/r/nats-io/nats-streaming-server?branch=master [Coverage-image]: https://coveralls.io/repos/github/nats-io/nats-streaming-server/badge.svg?branch=master&t=kIxrDE [ReportCard-Url]: http://goreportcard.com/report/nats-io/nats-streaming-server diff --git a/server/server.go b/server/server.go index d578acb5..b6d24e75 100644 --- a/server/server.go +++ b/server/server.go @@ -1714,14 +1714,17 @@ func RunServerWithOpts(stanOpts *Options, natsOpts *server.Options) (newServer * // We used to issue panic for common errors but now return error // instead. Still we want to log the reason for the panic. if r := recover(); r != nil { - s.Shutdown() s.log.Noticef("Failed to start: %v", r) + // For tests, we still shutdown server even before panic since + // some tests will do a recover(). + s.Shutdown() panic(r) } else if returnedError != nil { - s.Shutdown() // Log it as a fatal error, process will exit (if // running from executable or logger is configured). s.log.Fatalf("Failed to start: %v", returnedError) + // For tests, we call shutdown() for proper cleanup. + s.Shutdown() } }() diff --git a/server/server_run_test.go b/server/server_run_test.go index a115ac38..5fa2d24f 100644 --- a/server/server_run_test.go +++ b/server/server_run_test.go @@ -60,7 +60,7 @@ func TestRunServer(t *testing.T) { } func TestRunServerFailureLogsCause(t *testing.T) { - d := &dummyLogger{} + d := &captureFatalLogger{} sOpts := GetDefaultOptions() sOpts.NATSServerURL = "nats://127.0.0.1:4444" @@ -72,8 +72,9 @@ func TestRunServerFailureLogsCause(t *testing.T) { s.Shutdown() t.Fatal("Expected error, got none") } + // We should get a trace in the log - if !strings.Contains(d.msg, "available for connection") { + if !strings.Contains(d.fatal, "available for connection") { t.Fatalf("Expected to get a cause as invalid connection, got: %v", d.msg) } }