Skip to content

Commit

Permalink
Merge pull request #5322 from hashicorp/backport/jbrandhorst-fix-star…
Browse files Browse the repository at this point in the history
…tup-http-request-crash/positively-modern-marten

This pull request was automerged via backport-assistant
  • Loading branch information
hc-github-team-secure-boundary authored Dec 4, 2024
2 parents 6bbb104 + e6768b7 commit abd78e3
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 2 deletions.
8 changes: 6 additions & 2 deletions internal/event/eventer.go
Original file line number Diff line number Diff line change
Expand Up @@ -794,14 +794,18 @@ func (e *Eventer) ReleaseGate() error {
if qe == nil {
continue // we may have already sent this but gotten errors later
}
ctx, cancel := newSendCtx(qe.ctx)
if cancel != nil {
defer cancel()
}
var queuedOp string
switch t := qe.event.(type) {
case *sysEvent:
queuedOp = "system"
writeErr = e.writeSysEvent(qe.ctx, t, WithNoGateLocking(true))
writeErr = e.writeSysEvent(ctx, t, WithNoGateLocking(true))
case *err:
queuedOp = "error"
writeErr = e.writeError(qe.ctx, t, WithNoGateLocking(true))
writeErr = e.writeError(ctx, t, WithNoGateLocking(true))
default:
// Have no idea what this is and shouldn't have gotten in here to
// begin with, so just continue, and log it
Expand Down
45 changes: 45 additions & 0 deletions internal/event/eventer_gate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,3 +159,48 @@ func TestEventer_Gating(t *testing.T) {
})
}
}

func TestReleaseGate_NoError_CanceledContext(t *testing.T) {
require := require.New(t)

buffer := new(bytes.Buffer)
eventerConfig := EventerConfig{
AuditEnabled: true,
ObservationsEnabled: true,
SysEventsEnabled: true,
Sinks: []*SinkConfig{
{
Name: "test-sink",
EventTypes: []Type{EveryType},
Format: TextHclogSinkFormat,
Type: WriterSink,
WriterConfig: &WriterSinkTypeConfig{
Writer: buffer,
},
},
},
}
testLock := &sync.Mutex{}
testLogger := testLogger(t, testLock)

eventer, err := NewEventer(
testLogger,
testLock,
"TestEventer_Gating",
eventerConfig,
WithGating(true),
)
require.NoError(err)

ctx, cancel := context.WithCancel(context.Background())
t.Cleanup(cancel)
ctx, err = NewEventerContext(ctx, eventer)
require.NoError(err)

WriteError(ctx, "error-1", fmt.Errorf("error-1"))
_ = WriteObservation(ctx, "observation-1", WithId("observation-1"), WithHeader("foo", "bar"))

cancel()

require.NoError(eventer.ReleaseGate())
}

0 comments on commit abd78e3

Please sign in to comment.