Skip to content

Commit

Permalink
socket_listener: fix socket initialization on TLS connections
Browse files Browse the repository at this point in the history
When socket is a TLS socket, all the configured socket-level settings would fail (read_buffer_size & keep_alive_period).

fixes influxdata#13046
  • Loading branch information
phemmer committed Apr 6, 2023
1 parent 35edd18 commit 8b86ee8
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion plugins/inputs/socket_listener/stream_listener.go
Expand Up @@ -82,6 +82,10 @@ func (l *streamListener) setupUnix(u *url.URL, tlsCfg *tls.Config, socketMode st
}

func (l *streamListener) setupConnection(conn net.Conn) error {
if c, ok := conn.(*tls.Conn); ok {
conn = c.NetConn()
}

if l.ReadBufferSize > 0 {
if rb, ok := conn.(hasSetReadBuffer); ok {
if err := rb.SetReadBuffer(l.ReadBufferSize); err != nil {
Expand All @@ -104,7 +108,7 @@ func (l *streamListener) setupConnection(conn net.Conn) error {
if l.KeepAlivePeriod != nil {
tcpConn, ok := conn.(*net.TCPConn)
if !ok {
return fmt.Errorf("connection not a TCP connection (%T)", conn)
return fmt.Errorf("cannot set keep-alive: not a TCP connection (%T)", conn)
}
if *l.KeepAlivePeriod == 0 {
if err := tcpConn.SetKeepAlive(false); err != nil {
Expand Down

0 comments on commit 8b86ee8

Please sign in to comment.