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(filter): Fixed multiple connections closing in Moira-Filter caused by PR-562. #570

Merged
Changes from all commits
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
11 changes: 7 additions & 4 deletions filter/connection/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,13 @@ func (handler *Handler) HandleConnection(connection net.Conn, lineChan chan<- []

func (handler *Handler) handle(connection net.Conn, lineChan chan<- []byte) {
buffer := bufio.NewReader(connection)

closeConnection := make(chan struct{})
go func(conn net.Conn) {
<-handler.terminate
conn.Close()
select {
case <-handler.terminate:
conn.Close()
case <-closeConnection:
}
}(connection)

for {
Expand All @@ -48,7 +51,7 @@ func (handler *Handler) handle(connection net.Conn, lineChan chan<- []byte) {
if err != io.EOF {
handler.logger.Errorf("Fail to read from metric connection: %s", err)
}
handler.terminate <- struct{}{}
close(closeConnection)
return
}
bytesWithoutCRLF := dropCRLF(bytes)
Expand Down