Skip to content

Commit

Permalink
Fix https_batch deadlock due to golang timer changes
Browse files Browse the repository at this point in the history
  • Loading branch information
nicklas-dohrn committed Dec 13, 2024
1 parent 58e63a4 commit 5e8242f
Showing 1 changed file with 19 additions and 17 deletions.
36 changes: 19 additions & 17 deletions src/pkg/egress/syslog/https_batch.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,34 +65,36 @@ func (w *HTTPSBatchWriter) Write(env *loggregator_v2.Envelope) error {
}

func (w *HTTPSBatchWriter) startSender() {
t := time.NewTimer(w.sendInterval)

var msgBatch bytes.Buffer
var msgCount float64
reset := func() {
msgBatch.Reset()
msgCount = 0
t.Reset(w.sendInterval)
ticker := time.NewTicker(w.sendInterval)

msgCount = 0

sendBatch := func() {
if msgBatch.Len() > 0 {
w.sendHttpRequest(msgBatch.Bytes(), msgCount)
msgBatch.Reset()
msgCount = 0
}
}

for {
select {
case msg := <-w.msgs:
length, buffer_err := msgBatch.Write(msg)
_, 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)
reset()
log.Printf("Failed to write to buffer, dropping buffer of size %d , err: %s", msgBatch.Len(), buffer_err)
msgBatch.Reset()
msgCount = 0
} else {
msgCount++
if length >= w.batchSize {
w.sendHttpRequest(msgBatch.Bytes(), msgCount) //nolint:errcheck
reset()
if msgBatch.Len() >= w.batchSize {
sendBatch()
}
}
case <-t.C:
if msgBatch.Len() > 0 {
w.sendHttpRequest(msgBatch.Bytes(), msgCount) //nolint:errcheck
reset()
}
case <-ticker.C:
sendBatch()
}
}
}

0 comments on commit 5e8242f

Please sign in to comment.