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

panic: runtime error: SIGSEGV when permission denied on log file #1244

Closed
oernii opened this issue Mar 10, 2023 · 2 comments
Closed

panic: runtime error: SIGSEGV when permission denied on log file #1244

oernii opened this issue Mar 10, 2023 · 2 comments

Comments

@oernii
Copy link

oernii commented Mar 10, 2023

Describe the bug
App crashes when zap tries to create a logfile in a directory where there user has no permission to write

To Reproduce

  • have non-root user
  • start app in / for example or any non-writable dir
  • crash:
 panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x6b95ca]

goroutine 1 [running]:
go.uber.org/zap.(*Logger).check(0x0, 0x0, {0x74735b, 0x17})
        /root/go/pkg/mod/go.uber.org/zap@v1.23.0/logger.go:291 +0x6a
go.uber.org/zap.(*Logger).Info(0xc0000186b8?, {0x74735b?, 0x0?}, {0x0, 0x0, 0x0})
        /root/go/pkg/mod/go.uber.org/zap@v1.23.0/logger.go:212 +0x3b
main.main()
        /builds/build/app/main.go:30 +0x1a5

Expected behavior
Zap should crash with an "permission denied" error, not SEGV

Additional context
Similar to #390

@JacobOaks
Copy link
Contributor

JacobOaks commented Mar 10, 2023

Hey, thanks for reporting this.

How are you building your logger? The crash is indicating to me that the logger itself is nil. I was able to reproduce this by creating a logger from a config with a sink to a file in / but all I had to do to avoid the nil dereference was check for an error from Config.Build():

func main() {
    conf := zap.NewProductionConfig()
    conf.OutputPaths = append(conf.OutputPaths, "/output.log")
    logger, err := conf.Build()
    if err != nil {
        fmt.Printf("err creating logger: %v\n", err)
        return
    }
    defer logger.Sync()
    logger.Info("my log msg")
    // ...
}

Output:
err creating logger: open sink "/output.log": open /output.log: permission denied

@oernii
Copy link
Author

oernii commented Mar 13, 2023

That worked nicely, thanks for the hint.

@oernii oernii closed this as completed Mar 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants