Skip to content

Commit 0c7b4a4

Browse files
committed
Merge pull request #13 from arnecls/master
Fix for server.Kill() on UDP connections
2 parents 022467b + 75730d2 commit 0c7b4a4

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

server.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -217,8 +217,9 @@ func (s *Server) Kill() error {
217217
}
218218
}
219219
// Only need to close channel once to broadcast to all waiting
220-
close(s.doneTcp)
221-
220+
if s.doneTcp != nil {
221+
close(s.doneTcp)
222+
}
222223
return nil
223224
}
224225

server_test.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,20 @@ func (s *ServerSuite) TestConnectionClose(c *C) {
121121
}
122122
}
123123

124+
func (s *ServerSuite) TestConnectionUDPKill(c *C) {
125+
for _, closeConnection := range []bool{true, false} {
126+
handler := new(HandlerMock)
127+
server := NewServer()
128+
server.SetFormat(RFC5424)
129+
server.SetHandler(handler)
130+
con := ConnMock{ReadData: []byte(exampleSyslog)}
131+
server.goScanConnection(&con, closeConnection)
132+
server.Kill()
133+
server.Wait()
134+
c.Check(con.isClosed, Equals, closeConnection)
135+
}
136+
}
137+
124138
func (s *ServerSuite) TestTcpTimeout(c *C) {
125139
handler := new(HandlerMock)
126140
server := NewServer()

0 commit comments

Comments
 (0)