xcaddy: xcaddy does not download newly published module versions, even when specified

I published a new version of my module by tagging it and pushing the tag to GH, and immediately tried to xcaddy build with it like xcaddy build --with github.com/infogulch/my-module@v0.0.2, but xcaddy continued to use the old module version. After I manually updated the go proxy service with go get github.com/infogulch/my-module@v0.0.2 then it pulled in the new version. (See https://proxy.golang.org/#faq-new-version)

Some issues:

  • I would expect xcaddy build --with module@version to download new module versions like go get module@version does.
  • I would expect xcaddy to complain and fail to build if it didn’t find the version I specify, instead of just building with whatever other version it happens to find instead.

I expect this to reproduce with the following steps:

  1. Create a new module and publish a version
    1. Create new repo containing a caddy module
    2. Tag an initial version git tag -a v0.0.1; git push --tags
    3. Add it to the proxy go get my-module@v0.0.1
    4. Verify that it builds in caddy xcaddy build --with my-module@v0.0.1
  2. Publish a new version
    1. git commit ...; git tag -a v0.0.2; git push --tags
    2. Do not manually fetch it with go get
    3. Try to xcaddy build with the new version xcaddy build --with my-module@v0.0.2
    4. Observe in the build logs that it is still using v0.0.1

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 1
  • Comments: 18 (10 by maintainers)

Commits related to this issue

Most upvoted comments

Oh my mistake, the args are (string to check, prefix) not the reverse. Maybe this?:

if strings.HasPrefix(p.PackagePath, repl+“/”) {

🤔 I’ve been fiddling around with this today, locally this seems to have gotten me on the right track. Fingers crossed, maybe a PR later this evening 🐱

I figured the culprit line. Here xcaddy loops over all plugins/dependencies to execute go get against them:

https://github.com/caddyserver/xcaddy/blob/33391103931bd395b98c11e6cf7af8e9b95f90e7/environment.go#L181-L196

Critically, in this segment xcaddy skips replaced modules by checking if the package path of this iteration is prefixed by a package path that is replaced, i.e. if the current package path is github.com/infogulch/xtemplate-caddy and the replaced package is github.com/infogulch/xtemplate, then … oops

https://github.com/caddyserver/xcaddy/blob/33391103931bd395b98c11e6cf7af8e9b95f90e7/environment.go#L183-L191

The assumption made during the write of the tool is written in the comment. Our assumption is apparently not optimal. I don’t have an immediate solution from the top of my head right now. If you (or any passerby) figures it out, feel free to share.

I can think of a few ugly workarounds…

This is strange because xcaddy isn’t doing anything special. It’s a wrapper around go command, and it does call go get with the module path and version:

https://github.com/caddyserver/xcaddy/blob/eb894be6a004097e5ef67db4d8bcdb579d8ae1b8/environment.go#L182-L193

xcaddy cannot know to fail or complain if the go get command itself succeeds. I wonder if it’s local build cache issue… but it’s a clean env 🤔

Ah, haha thanks Mohammed. We might be better off checking for prefix match plus “/” or EOS. I’ve done this a few times before but this code was written before I was so wise 🙃

So maybe the issue is that if one module has a directory override, then it ignores version specifiers for other named modules?

Oh, ok, I see it now. When you had the local override, the next module was skipped for some reason. I’m thinking this is an unintentional bug, one of those infamous off-by-one error. Let’s check it.

Thanks; from the logs:

go: downloading github.com/caddyserver/caddy v1.0.5

That’s weird. It then downloads caddy/v2, but it shouldn’t be getting v1 at all… I would check your plugins for correctness here…

Mohammed is right though; xcaddy literally just wraps the go command, so I’m not sure if we’re the best situated to troubleshoot this. I’m not really sure what’s going on. 🤷‍♂

(Closing, since I don’t think there’s anything we can fix in xcaddy for this, but feel free to continue discussion!)