Skip to content

Commit

Permalink
temp fix for deadlock
Browse files Browse the repository at this point in the history
  • Loading branch information
nicklas-dohrn committed Dec 12, 2024
1 parent 58e63a4 commit abd9638
Showing 1 changed file with 15 additions and 11 deletions.
26 changes: 15 additions & 11 deletions src/pkg/egress/syslog/https_batch.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,24 +69,28 @@ func (w *HTTPSBatchWriter) startSender() {

var msgBatch bytes.Buffer
var msgCount float64

reset := func() {
if !t.Stop() {
<-t.C // Drain the timer channel if already expired
}
t.Reset(w.sendInterval)
msgBatch.Reset()
msgCount = 0
t.Reset(w.sendInterval)
}

for {
select {
case msg := <-w.msgs:
length, buffer_err := msgBatch.Write(msg)
if buffer_err != nil {
log.Printf("Failed to write to buffer, dropping buffer of size %d , err: %s", length, buffer_err)
case msg, ok := <-w.msgs:
if !ok {
log.Println("Channel closed, stopping sender")
return
}
msgBatch.Write(msg)
msgCount++
if msgBatch.Len() >= w.batchSize {
w.sendHttpRequest(msgBatch.Bytes(), msgCount) //nolint:errcheck
reset()
} else {
msgCount++
if length >= w.batchSize {
w.sendHttpRequest(msgBatch.Bytes(), msgCount) //nolint:errcheck
reset()
}
}
case <-t.C:
if msgBatch.Len() > 0 {
Expand Down

0 comments on commit abd9638

Please sign in to comment.