sillygod / cdp-cache

a caddy 2 proxy cache plugin
MIT License
120 stars 18 forks source link

panic: interface conversion: interface {} is nil, not *caddyhttp.Server #52

Closed cloudwindy closed 1 year ago

cloudwindy commented 2 years ago
panic: interface conversion: interface {} is nil, not *caddyhttp.Server

goroutine 55 [running]:
github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy.(*Handler).reverseProxy(0xc000124300, {0x7fdfc555d1b0, 0xc000690090}, 0xc00025fb00, 0xc00025fa00, 0xc00037ed40, {0xc00003b500, {0x1a32780, 0x3}, {0xc00003ff20, ...}, ...}, ...)
    github.com/caddyserver/caddy/v2@v2.5.1/modules/caddyhttp/reverseproxy/reverseproxy.go:730 +0x189d
github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy.(*Handler).proxyLoopIteration(0xc000124300, 0xc00025fb00, 0x1?, {0x7fdfc555d1b0, 0xc000690090}, {0x0, 0x0}, {0xc09dab3606b7f048, 0x1bf03c58, 0x2a16ec0}, ...)
    github.com/caddyserver/caddy/v2@v2.5.1/modules/caddyhttp/reverseproxy/reverseproxy.go:526 +0xf30
github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy.(*Handler).ServeHTTP(0xc000124300, {0x7fdfc555d1b0, 0xc000690090}, 0xc00025fa00, {0x1db0ac0, 0x1b4b6b8})
    github.com/caddyserver/caddy/v2@v2.5.1/modules/caddyhttp/reverseproxy/reverseproxy.go:435 +0x3a5
github.com/caddyserver/caddy/v2/modules/caddyhttp.(*metricsInstrumentedHandler).ServeHTTP(0xc0000ae700, {0x1db9e58?, 0xc00048dcc0}, 0xc00025fa00, {0x1db0ac0, 0x1b4b6b8})
    github.com/caddyserver/caddy/v2@v2.5.1/modules/caddyhttp/metrics.go:132 +0x53b
github.com/caddyserver/caddy/v2/modules/caddyhttp.wrapMiddleware.func1.1({0x1db9e58?, 0xc00048dcc0?}, 0x1782a01?)
    github.com/caddyserver/caddy/v2@v2.5.1/modules/caddyhttp/routes.go:272 +0x3b
github.com/caddyserver/caddy/v2/modules/caddyhttp.HandlerFunc.ServeHTTP(0xc0004c9920?, {0x1db9e58?, 0xc00048dcc0?}, 0xc0003a8af0?)
    github.com/caddyserver/caddy/v2@v2.5.1/modules/caddyhttp/caddyhttp.go:57 +0x2f
github.com/sillygod/cdp-cache.(*Handler).fetchUpstream.func1(0xc00025f700, 0xc000125200?)
    github.com/sillygod/cdp-cache@v0.4.6/handler.go:124 +0x3dd
created by github.com/sillygod/cdp-cache.(*Handler).fetchUpstream
    github.com/sillygod/cdp-cache@v0.4.6/handler.go:103 +0x25e
cloudwindy commented 2 years ago

Caddyfile:

http_cache {
    cache_type file 
    path /data/cache
    match_path /
    match_header Content-Type image/vnd.microsoft.icon text/js text/css image/gif image/jpeg image/png
}

Dockerfile:

FROM caddy:builder AS builder

RUN xcaddy build \
    --with github.com/kirsch33/realip \
    --with github.com/sillygod/cdp-cache

FROM caddy:latest

COPY --from=builder /usr/bin/caddy /usr/bin/caddy
cloudwindy commented 2 years ago

The problem was that I was building from the latest version of caddy.

cloudwindy commented 2 years ago

Let's keep this open as this won't work with v2.5.1.

sillygod commented 2 years ago

Let's keep this open as this won't work with v2.5.1.

Thanks for noting this package is not compatible with the caddy v2.5.1.

However, keeping updated with the latest version of caddy is not in high priority! It may be upgraded someday.

tve commented 2 years ago

I hit the same issue. Is it realty that much work to update? From a usage point of view it's the difference between being able to just download a caddy binary with the cdp-cache module vs. having to set-up a whole compilation environment...

PythonLinks commented 2 years ago

I made so many failed attempts to compile it. I am not a go developer. Kind of delayed my caching by 9 months Did not have much traffic, so was not a hot issue.

With Bastille containers, I got it compiling really quickly. Created a container, installed some tools, and then downloaded the go executable. It was so easy. When I got it wrong, I just deleted the container and repeated. I could not do that with my regular development environment.

In fact I would be happy to publish my Bastille container, if anyone is interested.

There is a larger problem at work here. You will see that the cache-handler software is under the auspices of /caddy-server. It supports distributed caches.

The cdp-cache is kind of abandoned. Lives on a less famous location. Not updated since April 8th. Requires an old version of Go and an old version of caddy.

Even though it is much simpler, and the docs are much much better.

My take away is that open source goes where the money is. Large companies that need distributed caches. Which is different from the needs of small companies, that just run on a single server.

I see the same issue everywhere. The needs of big and small companies are different. Here is my article about the difference between Docker and bsd. "Docker is for big companies, Bastille BSD is for small companies and developers. "

https://forestwiki.com/bastille-vs-docker

tve commented 2 years ago

Just as a heads-up, building caddy is not that easy... To install xcaddy I had to use:

go install github.com/caddyserver/xcaddy/cmd/xcaddy@latest

And I built caddy:

xcaddy build v2.4.1 --with github.com/sillygod/cdp-cache

But just running the executable to get help:

/h/s/caddy> ./caddy                                                                                 
panic: qtls.CertificateRequestInfo doesn't match                                                    

goroutine 1 [running]:                                                                              
github.com/marten-seemann/qtls-go1-16.init.0()                                                      
        github.com/marten-seemann/qtls-go1-16@v0.1.3/unsafe.go:17 +0x198                            

From https://github.com/caddyserver/caddy/issues/4118 I gather I have to use an older version of Go, perhaps...

PythonLinks commented 2 years ago

Yes, you have to use go 1.17 I had huge problems with the builds. Mostly because I am not a go developer. And I did not want to cause trouble in my development environment.

I submitted a read me pull request, and offered to make more edits, but have not heard back about the existing changes I made, so not much point investing a lot more effort into it.

Hopefully eventually they will respond to it.

korniychuk commented 1 year ago

For now, I managed to build this extension with Go v1.17 (MacOS). xcaddy build v2.4.6 --with github.com/sillygod/cdp-cache

sillygod commented 1 year ago

cdp-cache is upgraded (#67 ) so close this issue