Add stack trace to audit logging panic recovery (#18121)
This commit is contained in:
parent
b03da5157e
commit
48987ce052
|
@ -0,0 +1,3 @@
|
||||||
|
```release-note:improvement
|
||||||
|
audit: Include stack trace when audit logging recovers from a panic.
|
||||||
|
```
|
|
@ -3,6 +3,7 @@ package vault
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"runtime/debug"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
@ -105,7 +106,7 @@ func (a *AuditBroker) LogRequest(ctx context.Context, in *logical.LogInput, head
|
||||||
|
|
||||||
defer func() {
|
defer func() {
|
||||||
if r := recover(); r != nil {
|
if r := recover(); r != nil {
|
||||||
a.logger.Error("panic during logging", "request_path", in.Request.Path, "error", r)
|
a.logger.Error("panic during logging", "request_path", in.Request.Path, "error", r, "stacktrace", string(debug.Stack()))
|
||||||
retErr = multierror.Append(retErr, fmt.Errorf("panic generating audit log"))
|
retErr = multierror.Append(retErr, fmt.Errorf("panic generating audit log"))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -176,7 +177,7 @@ func (a *AuditBroker) LogResponse(ctx context.Context, in *logical.LogInput, hea
|
||||||
|
|
||||||
defer func() {
|
defer func() {
|
||||||
if r := recover(); r != nil {
|
if r := recover(); r != nil {
|
||||||
a.logger.Error("panic during logging", "request_path", in.Request.Path, "error", r)
|
a.logger.Error("panic during logging", "request_path", in.Request.Path, "error", r, "stacktrace", string(debug.Stack()))
|
||||||
retErr = multierror.Append(retErr, fmt.Errorf("panic generating audit log"))
|
retErr = multierror.Append(retErr, fmt.Errorf("panic generating audit log"))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,7 @@ import (
|
||||||
"context"
|
"context"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"runtime"
|
"runtime/debug"
|
||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
@ -41,12 +41,8 @@ func (s *forwardedRequestRPCServer) ForwardRequest(ctx context.Context, freq *fo
|
||||||
|
|
||||||
runRequest := func() {
|
runRequest := func() {
|
||||||
defer func() {
|
defer func() {
|
||||||
// Logic here comes mostly from the Go source code
|
|
||||||
if err := recover(); err != nil {
|
if err := recover(); err != nil {
|
||||||
const size = 64 << 10
|
s.core.logger.Error("panic serving forwarded request", "path", req.URL.Path, "error", err, "stacktrace", string(debug.Stack()))
|
||||||
buf := make([]byte, size)
|
|
||||||
buf = buf[:runtime.Stack(buf, false)]
|
|
||||||
s.core.logger.Error("panic serving forwarded request", "path", req.URL.Path, "error", err, "stacktrace", string(buf))
|
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
s.handler.ServeHTTP(w, req)
|
s.handler.ServeHTTP(w, req)
|
||||||
|
|
Loading…
Reference in New Issue