Skip to content

Commit 71ae45e

Browse files
committed
avoid close new connection
Signed-off-by: bnyu <xuyue1106@gmail.com>
1 parent f0ea9f5 commit 71ae45e

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

fluent/fluent.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ func (f *Fluent) Close() (err error) {
296296
close(f.pending)
297297
f.wg.Wait()
298298
}
299-
f.close()
299+
f.close(f.conn)
300300
return
301301
}
302302

@@ -311,9 +311,9 @@ func (f *Fluent) appendBuffer(msg *msgToSend) error {
311311
}
312312

313313
// close closes the connection.
314-
func (f *Fluent) close() {
314+
func (f *Fluent) close(c net.Conn) {
315315
f.muconn.Lock()
316-
if f.conn != nil {
316+
if f.conn != nil && f.conn == c {
317317
f.conn.Close()
318318
f.conn = nil
319319
}
@@ -386,7 +386,7 @@ func (f *Fluent) write(msg *msgToSend) error {
386386
}
387387
_, err := c.Write(msg.data)
388388
if err != nil {
389-
f.close()
389+
f.close(c)
390390
} else {
391391
// Acknowledgment check
392392
if msg.ack != "" {
@@ -399,7 +399,7 @@ func (f *Fluent) write(msg *msgToSend) error {
399399
err = resp.DecodeMsg(r)
400400
}
401401
if err != nil || resp.Ack != msg.ack {
402-
f.close()
402+
f.close(c)
403403
continue
404404
}
405405
}

0 commit comments

Comments
 (0)