Skip to content

Panic if TLS fluentd server cannot be connected #119

Open
@richarticle

Description

@richarticle

Running below code will panic if fluentd server cannot be connected.

package main

import (
    "github.com/fluent/fluent-logger-golang/fluent"
)

func main() {
    f, _ := fluent.New(fluent.Config{FluentNetwork: "tls", FluentPort: 11111, FluentHost: "127.0.0.1", Async: false})
    f.Post("tag", map[string]string{"log": "msg"})
    f.Post("tag", map[string]string{"log": "msg"})
}
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x59b539]

goroutine 1 [running]:
crypto/tls.(*Conn).SetWriteDeadline(0xc00010baa8?, {0x5f3dd6?, 0x2c?, 0x0?})
        /usr/local/go/src/crypto/tls/conn.go:153 +0x19
github.com/fluent/fluent-logger-golang/fluent.(*Fluent).write.func3(0xc000122000, 0xc0000267b0)
        /home/oliver/go/pkg/mod/github.com/fluent/[email protected]/fluent/fluent.go:606 +0x10e
github.com/fluent/fluent-logger-golang/fluent.(*Fluent).write(0xc000122000, {0x6a8898?, 0xc0000180a8?}, 0xc0000267b0)
        /home/oliver/go/pkg/mod/github.com/fluent/[email protected]/fluent/fluent.go:611 +0xd7
github.com/fluent/fluent-logger-golang/fluent.(*Fluent).writeWithRetry(0xc000122000, {0x6a8898, 0xc0000180a8}, 0xc000026750?)
        /home/oliver/go/pkg/mod/github.com/fluent/[email protected]/fluent/fluent.go:558 +0x5c
github.com/fluent/fluent-logger-golang/fluent.(*Fluent).postRawData(0xc000122000?, 0x644ca5?)
        /home/oliver/go/pkg/mod/github.com/fluent/[email protected]/fluent/fluent.go:300 +0x5b
github.com/fluent/fluent-logger-golang/fluent.(*Fluent).EncodeAndPostData(0x614720?, {0x644ca5?, 0x644c81?}, {0x3?, 0xc0000167f0?, 0x7e7da0?}, {0x614720, 0xc000026750})
        /home/oliver/go/pkg/mod/github.com/fluent/[email protected]/fluent/fluent.go:283 +0xb5
github.com/fluent/fluent-logger-golang/fluent.(*Fluent).PostWithTime(0xc000122000, {0x644ca5?, 0x16365a5d5533203e?}, {0x638f20?, 0x1?, 0x7e7da0?}, {0x614840?, 0xc000026720})
        /home/oliver/go/pkg/mod/github.com/fluent/[email protected]/fluent/fluent.go:274 +0x4ee
github.com/fluent/fluent-logger-golang/fluent.(*Fluent).Post(0x614840?, {0x644ca5, 0x3}, {0x614840, 0xc000026720})
        /home/oliver/go/pkg/mod/github.com/fluent/[email protected]/fluent/fluent.go:226 +0x59
main.main()
        /home/oliver/go/projects/test/main.go:9 +0xdc

In Fluent.connect(), below line assigns f.conn a *tls.Conn object instead of net.Conn interface object. Therefore, "f.conn == nil" returns false even if tls.Conn is nil.

f.conn, err = tls.DialWithDialer(

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions