Graylog2 / go-gelf

GELF library for Go
http://godoc.org/github.com/Graylog2/go-gelf/gelf
MIT License
103 stars 64 forks source link

fixed bug. Multi routine call WriteMessage will make race for same bu… #30

Closed lpflpf closed 5 years ago

lpflpf commented 5 years ago
// issue.go
package main

import (
    "time"
    "gopkg.in/Graylog2/go-gelf.v2/gelf"
)

func main() {
    addr := ""
    writer, _ := gelf.NewTCPWriter(addr)
    parall := 10000
    goroutineSize := 100
    for q := 0; q < goroutineSize; q++ {
        go func() {
            for j := 0; j < parall/goroutineSize; j++ {
                writer.WriteMessage(&gelf.Message{
                    Version:  "1.0",
                    Host:     "hostname",
                    Short:    "-",
                    TimeUnix: float64(time.Now().UnixNano()),
                    Level:    6,
                    Facility: "",
                })
            }
        }()
    }
    select {}
}

run go run -race issue.go; will get DATA RACE WARNING. it is a bugfix: https://github.com/lpflpf/go-gelf/tree/v2

CLAassistant commented 5 years ago

CLA assistant check
Thank you for your submission, we really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

dennisoelkers commented 5 years ago

Hey @lpflpf, thanks for your submission. What is the reason you closed this PR?

lpflpf commented 5 years ago

It has a mistake in submission. It have been submited again.

https://github.com/Graylog2/go-gelf/pull/31