caddyserver / caddy

Fast and extensible multi-platform HTTP/1-2-3 web server with automatic HTTPS
https://caddyserver.com
Apache License 2.0
56.45k stars 3.96k forks source link

Caddy2 file-server panic #2845

Closed jungle-boogie closed 4 years ago

jungle-boogie commented 4 years ago

1. Which version of Caddy are you using (caddy -version)?

caddy2_beta8_windows_amd64.exe

2. What are you trying to do?

> .\caddy2_beta8_windows_amd64.exe file-server

3. What is your Caddyfile?

blank/non-existent

4. How did you run Caddy (give the full command and describe the execution environment)?

> .\caddy2_beta8_windows_amd64.exe file-server

Windows 10 go version go1.12.7 windows/amd64

5. Please paste any relevant HTTP request(s) here.

http://localhost:2019

6. What did you expect to see?

File browser on the webpage

7. What did you see instead (give full error messages and/or log)?

1.5724717179222696e+09  INFO   tls     cleaned up storage units
2019/10/30 14:41:57 Caddy 2 serving static files on :2015
2019/10/30 14:42:06 http: panic serving 127.0.0.1:52959: runtime error: invalid memory address or nil pointer dereference
goroutine 24 [running]:
net/http.(*conn).serve.func1(0xc0001be1e0)
        /usr/local/go/src/net/http/server.go:1767 +0x140
panic(0xcc52c0, 0x1506c80)
        /usr/local/go/src/runtime/panic.go:679 +0x1c0
github.com/caddyserver/caddy/v2/modules/caddyhttp.errLogValues(0xefe620, 0xc0001a69c0, 0xc0001742a0, 0xc000094700, 0xc0001ea000, 0x1, 0x4, 0xefe620)
        /Users/matt/Dev/pkg/mod/github.com/caddyserver/caddy/v2@v2.0.0-beta8/modules/caddyhttp/server.go:371 +0xca
github.com/caddyserver/caddy/v2/modules/caddyhttp.(*Server).ServeHTTP(0xc0001de820, 0xf0dfa0, 0xc0001742a0, 0xc000094700)
        /Users/matt/Dev/pkg/mod/github.com/caddyserver/caddy/v2@v2.0.0-beta8/modules/caddyhttp/server.go:144 +0x7a7
net/http.serverHandler.ServeHTTP(0xc0001741c0, 0xf0dfa0, 0xc0001742a0, 0xc000094500)
        /usr/local/go/src/net/http/server.go:2802 +0xab
net/http.(*conn).serve(0xc0001be1e0, 0xf10920, 0xc0001a6840)
        /usr/local/go/src/net/http/server.go:1890 +0x87c
created by net/http.(*Server).Serve
        /usr/local/go/src/net/http/server.go:2927 +0x395
2019/10/30 14:42:06 http: panic serving 127.0.0.1:52960: runtime error: invalid memory address or nil pointer dereference
goroutine 26 [running]:
net/http.(*conn).serve.func1(0xc0001be280)
        /usr/local/go/src/net/http/server.go:1767 +0x140
panic(0xcc52c0, 0x1506c80)
        /usr/local/go/src/runtime/panic.go:679 +0x1c0
github.com/caddyserver/caddy/v2/modules/caddyhttp.errLogValues(0xefe620, 0xc000242180, 0xc00025c000, 0xc00024a200, 0xc0001ea000, 0x1, 0x4, 0xefe620)
        /Users/matt/Dev/pkg/mod/github.com/caddyserver/caddy/v2@v2.0.0-beta8/modules/caddyhttp/server.go:371 +0xca
github.com/caddyserver/caddy/v2/modules/caddyhttp.(*Server).ServeHTTP(0xc0001de820, 0xf0dfa0, 0xc00025c000, 0xc00024a200)
        /Users/matt/Dev/pkg/mod/github.com/caddyserver/caddy/v2@v2.0.0-beta8/modules/caddyhttp/server.go:144 +0x7a7
net/http.serverHandler.ServeHTTP(0xc0001741c0, 0xf0dfa0, 0xc00025c000, 0xc00024a000)
        /usr/local/go/src/net/http/server.go:2802 +0xab
net/http.(*conn).serve(0xc0001be280, 0xf10920, 0xc000242000)
        /usr/local/go/src/net/http/server.go:1890 +0x87c
created by net/http.(*Server).Serve
        /usr/local/go/src/net/http/server.go:2927 +0x395
2019/10/30 14:42:06 http: panic serving 127.0.0.1:52961: runtime error: invalid memory address or nil pointer dereference
goroutine 51 [running]:
net/http.(*conn).serve.func1(0xc00029e000)
        /usr/local/go/src/net/http/server.go:1767 +0x140
panic(0xcc52c0, 0x1506c80)
        /usr/local/go/src/runtime/panic.go:679 +0x1c0
github.com/caddyserver/caddy/v2/modules/caddyhttp.errLogValues(0xefe620, 0xc0001a6b40, 0xc000174380, 0xc000094a00, 0xc0001ea000, 0x1, 0x4, 0xefe620)
        /Users/matt/Dev/pkg/mod/github.com/caddyserver/caddy/v2@v2.0.0-beta8/modules/caddyhttp/server.go:371 +0xca
github.com/caddyserver/caddy/v2/modules/caddyhttp.(*Server).ServeHTTP(0xc0001de820, 0xf0dfa0, 0xc000174380, 0xc000094a00)
        /Users/matt/Dev/pkg/mod/github.com/caddyserver/caddy/v2@v2.0.0-beta8/modules/caddyhttp/server.go:144 +0x7a7
net/http.serverHandler.ServeHTTP(0xc0001741c0, 0xf0dfa0, 0xc000174380, 0xc000094800)
        /usr/local/go/src/net/http/server.go:2802 +0xab
net/http.(*conn).serve(0xc00029e000, 0xf10920, 0xc0001a6a00)
        /usr/local/go/src/net/http/server.go:1890 +0x87c
created by net/http.(*Server).Serve
        /usr/local/go/src/net/http/server.go:2927 +0x395
2019/10/30 14:42:06 http: panic serving 127.0.0.1:52962: runtime error: invalid memory address or nil pointer dereference
goroutine 7 [running]:
net/http.(*conn).serve.func1(0xc000071180)
        /usr/local/go/src/net/http/server.go:1767 +0x140
panic(0xcc52c0, 0x1506c80)
        /usr/local/go/src/runtime/panic.go:679 +0x1c0
github.com/caddyserver/caddy/v2/modules/caddyhttp.errLogValues(0xefe620, 0xc00005e580, 0xc0002b8000, 0xc0000d0300, 0xc0001ea000, 0x1, 0x4, 0xefe620)
        /Users/matt/Dev/pkg/mod/github.com/caddyserver/caddy/v2@v2.0.0-beta8/modules/caddyhttp/server.go:371 +0xca
github.com/caddyserver/caddy/v2/modules/caddyhttp.(*Server).ServeHTTP(0xc0001de820, 0xf0dfa0, 0xc0002b8000, 0xc0000d0300)
        /Users/matt/Dev/pkg/mod/github.com/caddyserver/caddy/v2@v2.0.0-beta8/modules/caddyhttp/server.go:144 +0x7a7
net/http.serverHandler.ServeHTTP(0xc0001741c0, 0xf0dfa0, 0xc0002b8000, 0xc0000d0100)
        /usr/local/go/src/net/http/server.go:2802 +0xab
net/http.(*conn).serve(0xc000071180, 0xf10920, 0xc00005e400)
        /usr/local/go/src/net/http/server.go:1890 +0x87c
created by net/http.(*Server).Serve
        /usr/local/go/src/net/http/server.go:2927 +0x395
2019/10/30 14:42:06 http: panic serving 127.0.0.1:52963: runtime error: invalid memory address or nil pointer dereference
goroutine 52 [running]:
net/http.(*conn).serve.func1(0xc00029e0a0)
        /usr/local/go/src/net/http/server.go:1767 +0x140
panic(0xcc52c0, 0x1506c80)
        /usr/local/go/src/runtime/panic.go:679 +0x1c0
github.com/caddyserver/caddy/v2/modules/caddyhttp.errLogValues(0xefe620, 0xc000242300, 0xc00025c0e0, 0xc00024a600, 0xc0001ea000, 0x1, 0x4, 0xefe620)
        /Users/matt/Dev/pkg/mod/github.com/caddyserver/caddy/v2@v2.0.0-beta8/modules/caddyhttp/server.go:371 +0xca
github.com/caddyserver/caddy/v2/modules/caddyhttp.(*Server).ServeHTTP(0xc0001de820, 0xf0dfa0, 0xc00025c0e0, 0xc00024a600)
        /Users/matt/Dev/pkg/mod/github.com/caddyserver/caddy/v2@v2.0.0-beta8/modules/caddyhttp/server.go:144 +0x7a7
net/http.serverHandler.ServeHTTP(0xc0001741c0, 0xf0dfa0, 0xc00025c0e0, 0xc00024a400)
        /usr/local/go/src/net/http/server.go:2802 +0xab
net/http.(*conn).serve(0xc00029e0a0, 0xf10920, 0xc0002421c0)
        /usr/local/go/src/net/http/server.go:1890 +0x87c
created by net/http.(*Server).Serve
        /usr/local/go/src/net/http/server.go:2927 +0x395
2019/10/30 14:42:06 http: panic serving 127.0.0.1:52964: runtime error: invalid memory address or nil pointer dereference
goroutine 54 [running]:
net/http.(*conn).serve.func1(0xc00029e140)
        /usr/local/go/src/net/http/server.go:1767 +0x140
panic(0xcc52c0, 0x1506c80)
        /usr/local/go/src/runtime/panic.go:679 +0x1c0
github.com/caddyserver/caddy/v2/modules/caddyhttp.errLogValues(0xefe620, 0xc000242480, 0xc00025c1c0, 0xc00024a900, 0xc0001ea000, 0x1, 0x4, 0xefe620)
        /Users/matt/Dev/pkg/mod/github.com/caddyserver/caddy/v2@v2.0.0-beta8/modules/caddyhttp/server.go:371 +0xca
github.com/caddyserver/caddy/v2/modules/caddyhttp.(*Server).ServeHTTP(0xc0001de820, 0xf0dfa0, 0xc00025c1c0, 0xc00024a900)
        /Users/matt/Dev/pkg/mod/github.com/caddyserver/caddy/v2@v2.0.0-beta8/modules/caddyhttp/server.go:144 +0x7a7
net/http.serverHandler.ServeHTTP(0xc0001741c0, 0xf0dfa0, 0xc00025c1c0, 0xc00024a700)
        /usr/local/go/src/net/http/server.go:2802 +0xab
net/http.(*conn).serve(0xc00029e140, 0xf10920, 0xc000242340)
        /usr/local/go/src/net/http/server.go:1890 +0x87c
created by net/http.(*Server).Serve
        /usr/local/go/src/net/http/server.go:2927 +0x395
2019/10/30 14:42:06 http: panic serving 127.0.0.1:52965: runtime error: invalid memory address or nil pointer dereference
goroutine 56 [running]:
net/http.(*conn).serve.func1(0xc00029e1e0)
        /usr/local/go/src/net/http/server.go:1767 +0x140
panic(0xcc52c0, 0x1506c80)
        /usr/local/go/src/runtime/panic.go:679 +0x1c0
github.com/caddyserver/caddy/v2/modules/caddyhttp.errLogValues(0xefe620, 0xc000242600, 0xc00025c2a0, 0xc00024ac00, 0xc0001ea000, 0x1, 0x4, 0xefe620)
        /Users/matt/Dev/pkg/mod/github.com/caddyserver/caddy/v2@v2.0.0-beta8/modules/caddyhttp/server.go:371 +0xca
github.com/caddyserver/caddy/v2/modules/caddyhttp.(*Server).ServeHTTP(0xc0001de820, 0xf0dfa0, 0xc00025c2a0, 0xc00024ac00)
        /Users/matt/Dev/pkg/mod/github.com/caddyserver/caddy/v2@v2.0.0-beta8/modules/caddyhttp/server.go:144 +0x7a7
net/http.serverHandler.ServeHTTP(0xc0001741c0, 0xf0dfa0, 0xc00025c2a0, 0xc00024aa00)
        /usr/local/go/src/net/http/server.go:2802 +0xab
net/http.(*conn).serve(0xc00029e1e0, 0xf10920, 0xc0002424c0)
        /usr/local/go/src/net/http/server.go:1890 +0x87c
created by net/http.(*Server).Serve
        /usr/local/go/src/net/http/server.go:2927 +0x395
2019/10/30 14:42:06 http: panic serving 127.0.0.1:52966: runtime error: invalid memory address or nil pointer dereference
goroutine 58 [running]:
net/http.(*conn).serve.func1(0xc00029e280)
        /usr/local/go/src/net/http/server.go:1767 +0x140
panic(0xcc52c0, 0x1506c80)
        /usr/local/go/src/runtime/panic.go:679 +0x1c0
github.com/caddyserver/caddy/v2/modules/caddyhttp.errLogValues(0xefe620, 0xc0001a6cc0, 0xc000174460, 0xc000094d00, 0xc0001ea000, 0x1, 0x4, 0xefe620)
        /Users/matt/Dev/pkg/mod/github.com/caddyserver/caddy/v2@v2.0.0-beta8/modules/caddyhttp/server.go:371 +0xca
github.com/caddyserver/caddy/v2/modules/caddyhttp.(*Server).ServeHTTP(0xc0001de820, 0xf0dfa0, 0xc000174460, 0xc000094d00)
        /Users/matt/Dev/pkg/mod/github.com/caddyserver/caddy/v2@v2.0.0-beta8/modules/caddyhttp/server.go:144 +0x7a7
net/http.serverHandler.ServeHTTP(0xc0001741c0, 0xf0dfa0, 0xc000174460, 0xc000094b00)
        /usr/local/go/src/net/http/server.go:2802 +0xab
net/http.(*conn).serve(0xc00029e280, 0xf10920, 0xc0001a6b80)
        /usr/local/go/src/net/http/server.go:1890 +0x87c
created by net/http.(*Server).Serve
        /usr/local/go/src/net/http/server.go:2927 +0x395
2019/10/30 14:42:06 http: panic serving 127.0.0.1:52967: runtime error: invalid memory address or nil pointer dereference
goroutine 29 [running]:
net/http.(*conn).serve.func1(0xc0001be320)
        /usr/local/go/src/net/http/server.go:1767 +0x140
panic(0xcc52c0, 0x1506c80)
        /usr/local/go/src/runtime/panic.go:679 +0x1c0
github.com/caddyserver/caddy/v2/modules/caddyhttp.errLogValues(0xefe620, 0xc000242780, 0xc00025c380, 0xc00024af00, 0xc0001ea000, 0x1, 0x4, 0xefe620)
        /Users/matt/Dev/pkg/mod/github.com/caddyserver/caddy/v2@v2.0.0-beta8/modules/caddyhttp/server.go:371 +0xca
github.com/caddyserver/caddy/v2/modules/caddyhttp.(*Server).ServeHTTP(0xc0001de820, 0xf0dfa0, 0xc00025c380, 0xc00024af00)
        /Users/matt/Dev/pkg/mod/github.com/caddyserver/caddy/v2@v2.0.0-beta8/modules/caddyhttp/server.go:144 +0x7a7
net/http.serverHandler.ServeHTTP(0xc0001741c0, 0xf0dfa0, 0xc00025c380, 0xc00024ad00)
        /usr/local/go/src/net/http/server.go:2802 +0xab
net/http.(*conn).serve(0xc0001be320, 0xf10920, 0xc000242640)
        /usr/local/go/src/net/http/server.go:1890 +0x87c
created by net/http.(*Server).Serve
        /usr/local/go/src/net/http/server.go:2927 +0x395
2019/10/30 14:42:06 http: panic serving 127.0.0.1:52968: runtime error: invalid memory address or nil pointer dereference
goroutine 60 [running]:
net/http.(*conn).serve.func1(0xc00029e320)
        /usr/local/go/src/net/http/server.go:1767 +0x140
panic(0xcc52c0, 0x1506c80)
        /usr/local/go/src/runtime/panic.go:679 +0x1c0
github.com/caddyserver/caddy/v2/modules/caddyhttp.errLogValues(0xefe620, 0xc0001a6e40, 0xc000174540, 0xc000095000, 0xc0001ea000, 0x1, 0x4, 0xefe620)
        /Users/matt/Dev/pkg/mod/github.com/caddyserver/caddy/v2@v2.0.0-beta8/modules/caddyhttp/server.go:371 +0xca
github.com/caddyserver/caddy/v2/modules/caddyhttp.(*Server).ServeHTTP(0xc0001de820, 0xf0dfa0, 0xc000174540, 0xc000095000)
        /Users/matt/Dev/pkg/mod/github.com/caddyserver/caddy/v2@v2.0.0-beta8/modules/caddyhttp/server.go:144 +0x7a7
net/http.serverHandler.ServeHTTP(0xc0001741c0, 0xf0dfa0, 0xc000174540, 0xc000094e00)
        /usr/local/go/src/net/http/server.go:2802 +0xab
net/http.(*conn).serve(0xc00029e320, 0xf10920, 0xc0001a6d00)
        /usr/local/go/src/net/http/server.go:1890 +0x87c
created by net/http.(*Server).Serve
        /usr/local/go/src/net/http/server.go:2927 +0x395
1.5724717690140917e+09  INFO   shutting down   {"signal": "SIGINT"}
2019/10/30 14:42:49 [INFO][cache:0xc00010c8c0] Stopped certificate maintenance routine
1.5724717690160913e+09  INFO   shutdown done   {"signal": "SIGINT"}

8. Why is this a bug, and how do you think this should be fixed?

Panic in the application isn't good. file-server is listed as a feature in caddy v2: https://github.com/caddyserver/caddy/wiki/v2:-Documentation#file-server

9. What are you doing to work around the problem in the meantime?

Still playing with v2

10. Please link to any related issues, pull requests, and/or discussion.

None found.

Bonus: What do you use Caddy for? Why did you choose Caddy?

Easy!

mholt commented 4 years ago

Thank you for trying v2! And for filling out most of the issue template. :smile: Can you answer # 5 please? :) I am having trouble reproducing this with the given information.

And is the file that you're requesting on disk, have the right permissions, etc? How can I reproduce this?

jungle-boogie commented 4 years ago

Hi Matt,

Once caddy was started, I made an http request to localhost:2019 via Firefox. I then saw the panic in the powershell window. Caddy was started by my user, who has access to the files on disk.

mholt commented 4 years ago

@jungle-boogie Thanks, but I mean more specifically: does the file you're requesting exist? Can you send me the exact HTTP request (at least the path) and the list of files in the folder that you're running it from?

jungle-boogie commented 4 years ago

hi Matt,

I didn’t specify a file when I went to the webbrowser, just the root dir. I had many files in the same directory as caddy itself, as caddy was still in my downloads directory.

Maybe I’m doing something wrong. Do I need a caddy file, either JSON or v1 style? Do I need to post a caddy file prior to browsing to the URL? How exactly should file-server function and what should be the outcome?

mholt commented 4 years ago

Okay, so request path is /.

Please, do you have the file listing? I need to know what is in the directory if I am going to be able to reproduce the error.

mholt commented 4 years ago

Or at least tell me if there is an index file?

jungle-boogie commented 4 years ago

I may have made a mistake above. The docs show default port of 2015 and I'm pretty sure that's what I used in firefox, not 2019.

jungle-boogie commented 4 years ago

Sorry, I don't have a list of the files at this time. I'll re-test on Windows 10 tomorrow. There was no index file in the downloads directory.

mholt commented 4 years ago

Okay. Thanks, based on that I was able to track down what is likely the reason for the panic, and pushed a fix to the v2 branch. Try it out and let me know if it also works for you!

jungle-boogie commented 4 years ago

Okay, I have an update...

This also panics on Ubuntu when a request is made to /. When I specified a file, there was no panic.

$ touch matt
$ ./caddy2_beta8_linux_amd64 file-server
2019/10/30 21:12:25 [INFO][cache:0xc0001208c0] Started certificate maintenance routine
1.5724951456026516e+09  INFO    tls     cleaned up storage units
2019/10/30 21:12:25 Caddy 2 serving static files on :2015

browse to http://localhost:2015/matt

no panic

now delete /matt and browse, panic happens.

jungle-boogie commented 4 years ago

Verified fixed in 8d3c64932eddb42f7e5c4549555e9d12a559d552

Sorry for so much back and forth, and good job on fixing this.

mholt commented 4 years ago

Excellent, thank you for confirming!! I appreciate your time in getting that resolved.

tspivey commented 4 years ago

This issue is still present. From a directory with nothing in it except caddy, I ran: sudo ./caddy file-server >& log Connecting to it with curl http://localhost gives me this error.

{"level":"warn","ts":1586590736.400914,"logger":"admin","msg":"admin endpoint disabled"}
{"level":"info","ts":1586590736.4010906,"logger":"http","msg":"server is listening only on the HTTP port, so no automatic HTTPS will be applied to this server","server_name":"static","http_port":80}
{"level":"info","ts":1586590736.4016533,"logger":"tls","msg":"cleaned up storage units"}
2020/04/11 00:38:56 [INFO][cache:0xc0004da320] Started certificate maintenance routine
{"level":"info","ts":1586590736.4019477,"msg":"autosaved config","file":"/root/.config/caddy/autosave.json"}
2020/04/11 00:38:56 Caddy 2 serving static files on :80
2020/04/11 00:38:59 http: panic serving 127.0.0.1:49572: runtime error: invalid memory address or nil pointer dereference
goroutine 13 [running]:
net/http.(*conn).serve.func1(0xc0002c4d20)
    net/http/server.go:1772 +0x139
panic(0x144d380, 0x2470800)
    runtime/panic.go:975 +0x3e3
github.com/caddyserver/caddy/v2/modules/caddyhttp.(*Server).ServeHTTP(0xc0000ac360, 0x192e2e0, 0xc0007e8380, 0xc000417600)
    github.com/caddyserver/caddy/v2@v2.0.0-rc.2/modules/caddyhttp/server.go:203 +0x932
net/http.serverHandler.ServeHTTP(0xc0007e81c0, 0x192e2e0, 0xc0007e8380, 0xc000417300)
    net/http/server.go:2807 +0xa3
net/http.(*conn).serve(0xc0002c4d20, 0x19334e0, 0xc00012c840)
    net/http/server.go:1895 +0x86c
created by net/http.(*Server).Serve
    net/http/server.go:2933 +0x35c
{"level":"info","ts":1586590741.0869493,"msg":"shutting down","signal":"SIGINT"}
2020/04/11 00:39:01 [INFO][cache:0xc0004da320] Stopped certificate maintenance routine
{"level":"info","ts":1586590741.0872684,"msg":"shutdown done","signal":"SIGINT"}

Running on Ubuntu 19.10 x64, Caddy version: v2.0.0-rc.2 h1:7NOaxYrsnQ5D3rcLGn2UnLZHLfBpgrfM/JNTLhjCJ1c=

francislavoie commented 4 years ago

@tspivey Not the same issue. What you're seeing is the same as https://github.com/caddyserver/caddy/issues/3248 which has been fixed in the master branch. You can grab the latest build artifact from https://github.com/caddyserver/caddy/actions/runs/75592323 which has the fix.