Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

filename hook is not thread safe #9

Closed
davidklassen opened this issue Dec 13, 2018 · 2 comments · Fixed by #10
Closed

filename hook is not thread safe #9

davidklassen opened this issue Dec 13, 2018 · 2 comments · Fixed by #10

Comments

@davidklassen
Copy link
Contributor

This is an example that reproduces the problem.

package main

import (
	"github.com/onrik/logrus/filename"
	"github.com/sirupsen/logrus"
)

func main() {
	logger := logrus.New()
	logger.AddHook(filename.NewHook())
	l := logger.WithFields(logrus.Fields{"foo": "bar"})
	go func() {
		for {
			l.WithFields(nil)
		}
	}()
	go func() {
		for {
			l.Println("test")
		}
	}()
	for {
	}
}

Run it with go run -race main.go > /dev/null.
Looks like the problem is in the hook.Fire function that modifies entry.Data.

@onrik
Copy link
Owner

onrik commented Dec 17, 2018

Thanks. But i think it's read corner case when different goroutines modifying logrus.Entry data. Do you have any ideas how to fix it?

@davidklassen
Copy link
Contributor Author

Maybe implementing a custom formatter that clones entry.Data instead of modifying entry.Data directly can help. I'll try this approach and if it works I'll make a PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants