From ba649324f72ed8a5a6bdc4c62f6580aa79b82148 Mon Sep 17 00:00:00 2001 From: Jeff Mitchell Date: Fri, 14 Jul 2017 11:03:01 -0400 Subject: [PATCH] Opportunistically try re-opening file audit fd on error (#2999) Addresses a pain point from https://github.com/hashicorp/vault/issues/2863#issuecomment-309434605 --- builtin/audit/file/backend.go | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/builtin/audit/file/backend.go b/builtin/audit/file/backend.go index 0b05b0a3d3dc..4f39cc7bfb8f 100644 --- a/builtin/audit/file/backend.go +++ b/builtin/audit/file/backend.go @@ -159,6 +159,18 @@ func (b *Backend) LogRequest(auth *logical.Auth, req *logical.Request, outerErr return err } + if err := b.formatter.FormatRequest(b.f, b.formatConfig, auth, req, outerErr); err == nil { + return nil + } + + // Opportunistically try to re-open the FD, once per call + b.f.Close() + b.f = nil + + if err := b.open(); err != nil { + return err + } + return b.formatter.FormatRequest(b.f, b.formatConfig, auth, req, outerErr) } @@ -175,6 +187,18 @@ func (b *Backend) LogResponse( return err } + if err := b.formatter.FormatResponse(b.f, b.formatConfig, auth, req, resp, err); err == nil { + return nil + } + + // Opportunistically try to re-open the FD, once per call + b.f.Close() + b.f = nil + + if err := b.open(); err != nil { + return err + } + return b.formatter.FormatResponse(b.f, b.formatConfig, auth, req, resp, err) }