Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix https_batch deadlock due to golang timer changes #648

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 20 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,37 @@ 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)
defer ticker.Stop()

msgCount = 0

sendBatch := func() {
if msgBatch.Len() > 0 {
w.sendHttpRequest(msgBatch.Bytes(), msgCount)
ctlong marked this conversation as resolved.
Show resolved Hide resolved
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()
}
}
}
Loading