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

[Bug] latest upstream version is wrongly detected #1923

Closed
3 of 4 tasks
christian-heusel opened this issue May 2, 2024 · 6 comments
Closed
3 of 4 tasks

[Bug] latest upstream version is wrongly detected #1923

christian-heusel opened this issue May 2, 2024 · 6 comments
Labels
bug Something isn't working

Comments

@christian-heusel
Copy link
Contributor

Is this a support request?

  • This is not a support request

Is there an existing issue for this?

  • I have searched the existing issues

Current Behavior

2024-05-02T11:56:17Z WRN An updated version of Headscale has been found (0.23.0-alpha9 vs. your current v0.23.0-alpha11). Check it out https://github.com/juanfont/headscale/releases

Expected Behavior

No log message when on the latest version

Steps To Reproduce

  1. start up any headscale version later than 9
  2. observe the above warning

Environment

- OS: Debian trixie/sid with Headscale running in Docker
- Headscale version: v0.23.0-alpha11
- Tailscale version: -

Runtime environment

  • Headscale is behind a (reverse) proxy
  • Headscale runs in a container

Anything else?

With the relevant code inside of this project that is causing this behaviour being:

if (runtime.GOOS == "linux" || runtime.GOOS == "darwin") &&
Version != "dev" {
githubTag := &latest.GithubTag{
Owner: "juanfont",
Repository: "headscale",
}
res, err := latest.Check(githubTag, Version)
if err == nil && res.Outdated {
//nolint
log.Warn().Msgf(
"An updated version of Headscale has been found (%s vs. your current %s). Check it out https://github.com/juanfont/headscale/releases\n",
res.Current,
Version,
)
}
}
}

I have dug into the issue/code a little and found that the error seems to propagate from github.com/hashicorp/go-version or alteast the version that the tcnksm/go-latest dependency is using. I have come to this conclusion with this little test program:

package main

import (
	"fmt"

	"github.com/hashicorp/go-version"
	"github.com/rs/zerolog/log"
	"github.com/tcnksm/go-latest"
)

func main() {
	Version := "v0.23.0-alpha10"
	githubTag := &latest.GithubTag{
		Owner:      "juanfont",
		Repository: "headscale",
	}

	fetch, err := githubTag.Fetch()
	fmt.Println("Valid")
	for _, v := range fetch.Versions {
		fmt.Printf("%s\n", v)
	}

	fmt.Println("Malformed")
	for _, v := range fetch.Malformeds {
		fmt.Printf("%s\n", v)
	}

	fmt.Println("Versioncmp")
	ourV, err := version.NewVersion(Version)
	theirV, err := version.NewVersion("0.23.0-alpha9")

	fmt.Printf("versioncompare %s < %s == %t\n", ourV, theirV, ourV.LessThan(theirV))

	// Original code
	res, err := latest.Check(githubTag, Version)
	if err == nil && res.Outdated {
		log.Warn().Msgf(
			"An updated version of Headscale has been found (%s vs. your current %s). Check it out https://github.com/juanfont/headscale/releases\n",
			res.Current,
			Version,
		)
	}
}

Gives the following:

$ go run test.go
Valid
0.23.0-alpha-docker-release-test
0.23.0-alpha11
0.23.0-alpha10
0.23.0-alpha9
0.23.0-alpha8
0.23.0-alpha7
0.23.0-alpha6
0.23.0-alpha5
0.23.0-alpha4
0.23.0-alpha4-docker-ko-test9
0.23.0-alpha4-docker-ko-test8
0.23.0-alpha4-docker-ko-test7
0.23.0-alpha4-docker-ko-test6
0.23.0-alpha4-docker-ko-test5
0.23.0-alpha4-docker-ko-test4
0.23.0-alpha4-docker-ko-test3
0.23.0-alpha4-docker-ko-test2
0.23.0-alpha4-docker-ko-test
0.23.0-alpha3
0.23.0-alpha2
0.23.0-alpha1
0.22.3
0.22.2
0.22.1
0.22.0
0.22.0-nfpmtest
0.22.0-alpha3
0.22.0-alpha2
0.22.0-alpha1
0.21.0
Malformed
Versioncmp
versioncompare 0.23.0-alpha10 < 0.23.0-alpha9 == true
{"level":"warn","time":"2024-05-02T14:30:27+02:00","message":"An updated version of Headscale has been found (0.23.0-alpha9 vs. your current v0.23.0-alpha10). Check it out https://github.com/juanfont/headscale/releases\n"}

This shows a few things:

  1. The versions greater than 9 are detected by latest
  2. They are parsed valid and not sorted out because they are malformed
  3. For some reason 0.23.0-alpha10 < 0.23.0-alpha9 is true
@runejuhl
Copy link

Looks like it's a known issue, here are some issues in the https://github.com/hashicorp/go-version/ tracker that look like they're related. Unfortunately one of them is almost 5 years old.

Copy link
Contributor

This issue is stale because it has been open for 90 days with no activity.

@github-actions github-actions bot added the stale label Aug 16, 2024
@christian-heusel
Copy link
Contributor Author

This issue is stale, but only because there has been no fix so far, the issue itself still persists 😊

@github-actions github-actions bot removed the stale label Aug 17, 2024
@kradalby
Copy link
Collaborator

kradalby commented Sep 5, 2024

Thanks for the investigation, it looks like the easier proper way is to correct our incorrect use of semver.

we smash alpha and beta with the numbers, where it would be appropriate to have a . in between.

So we should do beta.4 for the next release and make sure we do alpha.1 and beta.1 for the next release.

I'm gonna close it as "this will be the solution". If that doesnt solve it we can reopen.

@kradalby
Copy link
Collaborator

kradalby commented Sep 9, 2024

Well this is fun:

#2058 (comment)

I think that we are kind of in a catch22, and I think that just getting to the next version will actually solve this better than attempting to rename tags.

From reading semver, we are now using the right approach, but the library likely does not parse things after the . when the number is in the same as the beta.

Hopefully this should be solved by doing a RC in a couple of days.

@kradalby kradalby reopened this Sep 9, 2024
@kradalby
Copy link
Collaborator

I think this should be resolved now with the release of 0.23.0, and I'll try to remember to do it properly from here on.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants