eclipse / paho.golang

Go libraries
Other
327 stars 92 forks source link

context.AfterFunc is not included in Go version 1.20.x , but used in this library. #241

Closed tomatod closed 6 months ago

tomatod commented 6 months ago

Thank you so much for developing this library. While I'm trying this library, There's a problem with test, so please let me an report. I'm sorry if i was wrong.

Describe the bug This library's go version is 1.20 (or later) according to go.mod, But context.AfterFunc is used in Connect function in paho/client.go .

But, context.AfterFunc is not included inGo version 1.20.x. It has been offered from version 1.21.x .

To reproduce After you switch to Go version 1.20.x and make test, you can get an error like the following.

$ go version
go version go1.20.13 linux/amd64

$ make test
go test -coverprofile /tmp/autopaho_coverage.out -race -tags=unittest ./autopaho/ -v -count 1
# github.com/eclipse/paho.golang/paho
paho/client.go:337:10: undefined: context.AfterFunc
FAIL    github.com/eclipse/paho.golang/autopaho [build failed]
FAIL
make: *** [Makefile:4: unittest] Error 1

Expected behaviour Test should be passed

Additional context The specified Go version in this library probably is required upgrading.

Best Regards,

MattBrittan commented 6 months ago

You are correct; it does use context.AfterFunc (I introduced this in January). I probably jumped the gun by a month or so on this. It would be possible to remove the call to context.AfterFunc but doing so would complicate things a bit, so I think it's best to just move to supporting v1.21+.

I aim to support Go releases that are supported by the Go team (i.e. current version and one previous version); however I really only test with the latest release and don't update go.mod unless I notice that I'm using a new feature. Now that Go 1.22 is out, we support Go 1.21+ and, as you say, should update the go.mod to reflect this.