spf13 / viper

Go configuration with fangs
MIT License
26.77k stars 2.01k forks source link

Backward incompatibility on FreeBSD10 and FreeBSD11 #1618

Closed douchen1 closed 12 months ago

douchen1 commented 1 year ago

Preflight Checklist

Viper Version

1.16.0

Go Version

1.19.7

Config Source

Files

Format

TOML

Repl.it link

No response

Code reproducing the issue

package main

import (
    "log"
    "os"

    "github.com/spf13/viper"
)

func main() {
    directory, _ := os.Getwd()
    configFile := directory + "/config.toml"
    viper.SetConfigFile(configFile)
    log.Printf("Using config file: %s", viper.ConfigFileUsed())
    viper.WatchConfig()
    log.Println("Done testing")
}

Expected Behavior

2023/01/01 00:00:00 Using config file: //config.toml 2023/01/01 00:00:00 Done testing

Actual Behavior

2023/01/01 00:00:00 Using config file: //config.toml ERROR 2023/01/01 00:00:00 failed to create watcher: function not implemented

Steps To Reproduce

  1. Using Go@1.19.7 1, compiles above .go file for FreeBSD AMD64 via env GOOS=freebsd GOARCH=amd64 go build -o <name>
  2. Create a config.toml file in the same level of the compiled binary.
  3. Run compiled binary under FreeBSD AMD64 v10.4

Additional Information

viper.WatchConfig() internally uses fsnotify, which communicates with Kernel to create Kernel Queues. That's where we observe backward incompatibility. It works fine in FreeBSD13, but fail at FreeBSD10 and FreeBSD11.

github-actions[bot] commented 1 year ago

👋 Thanks for reporting!

A maintainer will take a look at your issue shortly. 👀

In the meantime: We are working on Viper v2 and we would love to hear your thoughts about what you like or don't like about Viper, so we can improve or fix those issues.

⏰ If you have a couple minutes, please take some time and share your thoughts: https://forms.gle/R6faU74qPRPAzchZ9

📣 If you've already given us your feedback, you can still help by spreading the news, either by sharing the above link or telling people about this on Twitter:

https://twitter.com/sagikazarmark/status/1306904078967074816

Thank you! ❤️

sagikazarmark commented 1 year ago

My understanding is fsnotify does not work on FreeBSD. If that's not the case, we can probably adjust the build tags guarding against runtime errors: https://github.com/spf13/viper/blob/master/watch_unsupported.go

douchen1 commented 1 year ago
fmt.Errorf("fsnotify not supported on %s", runtime.GOOS)

Didn't see such error printout during testing. In fact, fsnotify do support FreeBSD https://github.com/fsnotify/fsnotify/blob/v1.6.0/backend_kqueue.go#L2

In early release of viper(v1.7.2-0.20201211163600-99da8b22a1c0), there's no issue running on FreeBSD10/FreeBSD11. The only difference of fsnotify.NewWatcher() used by different versions of viper(v1.7.2 and v1.16.0) is that, in newer version, we have closepipe as part of the watcher struct.

  1. viper@1.16 uses fsnotify@1.6.0 : https://github.com/fsnotify/fsnotify/blob/v1.6.0/backend_kqueue.go#L136
  2. viper@1.7.2 uses fsnotify@1.4.9 : https://github.com/fsnotify/fsnotify/blob/v1.4.9/kqueue.go#L45
sagikazarmark commented 1 year ago

Okay, I took a closer look. I probably spoke too soon, looks like FreeBSD is indeed supported by fsnotify.

I've been trying to figure out where this part of the error message comes: "function not implemented", but it's not Viper and apparently not fsnotify either.

A quick Google search led me to the following issue: golang/go#58914

Looks like FreeBSD 10 is not supported in Go 1.19. 11 should still be supported though: https://github.com/golang/go/wiki/FreeBSD#go-on-freebsd

Sadly I don't have a FreeBSD setup, so I can't really test it myself, but it looks like FreeBSD 10 is not supported anymore anyway (or something in the new fsnotify version uses a feature unsupported on it), FreeBSD 11 support is dropped after Go 1.19.

Viper tries to follow the Go support policy (although not strictly) that we support the last two Go versions, so chances are support for anything before 1.20 will be dropped at some point.

I'm sorry I don't have a better answer at this time.

douchen1 commented 12 months ago

Yes, I also found the same issue and wiki. However, I did test on FreeBSD 11 and it didn't work. Not sure if the GO wiki is out-of date or sth. So seems like the only solution now is to use FreeBSD13 instead of the older versions. Anyway, thanks for all the assistances.

sagikazarmark commented 12 months ago

@douchen1 sure, sorry I couldn't be of more help. The above linked issue also mentions that the FreeBSD wiki might be out of date.