Skip to content

Commit

Permalink
close all connections to client when shutdonw
Browse files Browse the repository at this point in the history
  • Loading branch information
childe committed Oct 20, 2024
1 parent 2811d7b commit 540982b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion input/input_box.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,6 @@ func (box *InputBox) shutdown() {

// Shutdown shutdowns the inputs and outputs
func (box *InputBox) Shutdown() {
box.shutdown()
box.stop = true
box.shutdown()
}
6 changes: 6 additions & 0 deletions input/tcp_input.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ type TCPInput struct {
l net.Listener
messages chan []byte
stop bool

connections []net.Conn
}

func readLine(scanner *bufio.Scanner, c net.Conn, messages chan<- []byte) {
Expand Down Expand Up @@ -86,6 +88,7 @@ func newTCPInput(config map[interface{}]interface{}) topology.Input {
}
klog.Error(err)
} else {
p.connections = append(p.connections, conn)
scanner := bufio.NewScanner(conn)
if v, ok := config["max_length"]; ok {
max := v.(int)
Expand All @@ -109,5 +112,8 @@ func (p *TCPInput) ReadOneEvent() map[string]interface{} {
func (p *TCPInput) Shutdown() {
p.stop = true
p.l.Close()
for _, conn := range p.connections {
conn.Close()
}
close(p.messages)
}

0 comments on commit 540982b

Please sign in to comment.