Skip to content

Commit

Permalink
Don't dial on backend startup; retry dials at log time so that transi…
Browse files Browse the repository at this point in the history
…ent (#2934)

network failures are worked around. Also, during a reconnect always
close the existing connection.

Fixes #2931
  • Loading branch information
jefferai authored Jul 6, 2017
1 parent c912a3e commit 4efff56
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions builtin/audit/socket/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,7 @@ func Factory(conf *audit.BackendConfig) (audit.Backend, error) {
logRaw = b
}

conn, err := net.Dial(socketType, address)
if err != nil {
return nil, err
}

b := &Backend{
connection: conn,
saltConfig: conf.SaltConfig,
saltView: conf.SaltView,
formatConfig: audit.FormatterConfig{
Expand Down Expand Up @@ -182,6 +176,12 @@ func (b *Backend) LogResponse(auth *logical.Auth, req *logical.Request,
}

func (b *Backend) write(buf []byte) error {
if b.connection == nil {
if err := b.reconnect(); err != nil {
return err
}
}

err := b.connection.SetWriteDeadline(time.Now().Add(b.writeDuration))
if err != nil {
return err
Expand All @@ -196,12 +196,16 @@ func (b *Backend) write(buf []byte) error {
}

func (b *Backend) reconnect() error {
if b.connection != nil {
b.connection.Close()
b.connection = nil
}

conn, err := net.Dial(b.socketType, b.address)
if err != nil {
return err
}

b.connection.Close()
b.connection = conn

return nil
Expand Down

0 comments on commit 4efff56

Please sign in to comment.