Skip to content

Commit

Permalink
Merge pull request #254 from childe/fix-tcp-input-reload
Browse files Browse the repository at this point in the history
Fix tcp input reload
  • Loading branch information
childe authored Oct 20, 2024
2 parents 37bad47 + 540982b commit 47e1c8e
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
7 changes: 3 additions & 4 deletions gohangout.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,15 +114,14 @@ func reload() {
klog.Errorf("could not parse config, ignore reload: %v", err)
return
}
klog.Info("stop old inputs")
inputs.stop()

boxes, err := buildPluginLink(gohangoutConfig)
if err != nil {
klog.Errorf("build plugin link error, ignore reload: %v", err)
return
}

klog.Info("stop old inputs")
inputs.stop()

inputs = gohangoutInputs(boxes)
klog.Info("start new inputs")
go inputs.start()
Expand Down
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 47e1c8e

Please sign in to comment.