Update the docs and move the logic for reconnecting into its own function

This commit is contained in:
Brian Kassouf 2017-02-04 16:55:17 -08:00
parent b38eeec96a
commit af1847f2b4
2 changed files with 27 additions and 9 deletions

View file

@ -8,6 +8,7 @@ import (
"sync"
"time"
multierror "github.com/hashicorp/go-multierror"
"github.com/hashicorp/vault/audit"
"github.com/hashicorp/vault/helper/duration"
"github.com/hashicorp/vault/logical"
@ -28,7 +29,7 @@ func Factory(conf *audit.BackendConfig) (audit.Backend, error) {
socketType = "tcp"
}
writeDeadline, ok := conf.Config["write_deadline"]
writeDeadline, ok := conf.Config["write_timeout"]
if !ok {
writeDeadline = "2s"
}
@ -119,13 +120,16 @@ func (b *Backend) LogRequest(auth *logical.Auth, req *logical.Request, outerErr
}
b.Lock()
defer b.Unlock()
b.connection.SetDeadline(time.Now().Add(b.writeDuration))
_, err := b.connection.Write(buf.Bytes())
b.Unlock()
if err != nil {
b.Reload()
rErr := b.reconnect()
if rErr != nil {
err = multierror.Append(err, rErr)
}
}
return err
@ -139,22 +143,22 @@ func (b *Backend) LogResponse(auth *logical.Auth, req *logical.Request,
}
b.Lock()
defer b.Unlock()
b.connection.SetDeadline(time.Now().Add(b.writeDuration))
_, err := b.connection.Write(buf.Bytes())
b.Unlock()
if err != nil {
b.Reload()
rErr := b.reconnect()
if rErr != nil {
err = multierror.Append(err, rErr)
}
}
return err
}
func (b *Backend) Reload() error {
b.Lock()
defer b.Unlock()
func (b *Backend) reconnect() error {
conn, err := net.Dial(b.socketType, b.address)
if err != nil {
return err
@ -165,3 +169,12 @@ func (b *Backend) Reload() error {
return nil
}
func (b *Backend) Reload() error {
b.Lock()
defer b.Unlock()
err := b.reconnect()
return err
}

View file

@ -67,6 +67,11 @@ Following are the configuration options available for the backend.
Allows selecting the output format. Valid values are `json` (the
default) and `jsonx`, which formats the normal log entries as XML.
</li>
<li>
<span class="param">write_timeout</span>
<span class="param-flags">optional</span>
Sets the timeout for writes to the socket. Defaults to "2s" (2 seconds).
</li>
</ul>
</dd>
</dl>