"runtime error: slice bounds out of range"

Caddy 0.10.4 on Archlinux. I saw multiple requests by a Google IP resulting in “runtime error: slice bounds out of range” errors.

Not sure if this is a bug, my config and if it is something I should be worried about?

I stripped some stuff when comparing multiple logs, if you need a full one just shout:

[stripped] http: panic serving 66.102.[stripped]:[stripped]: runtime error: slice bounds out of range
goroutine 205[stripped] [running]:
net/http.(*conn).serve.func1(0xc420[stripped])
        /usr/lib/go/src/net/http/server.go:1721 +0xd0
panic(0xa44a20, 0xe5d4f0)
        /usr/lib/go/src/runtime/panic.go:489 +0x2cf
github.com/mholt/caddy/caddyhttp/httpserver.getVersion(0xc420[stripped], 0x59, 0xaf5e01, 0x7, 0x1)
        /home/me/.cache/pacaur/caddy/src/build/src/github.com/mholt/caddy/caddyhttp/httpserver/mitm.go:116 +0x312
github.com/mholt/caddy/caddyhttp/httpserver.(*tlsHandler).ServeHTTP(0xc42035fcc0, 0xdfdd20, 0xc420[stripped], 0xc42[stripped])
        /home/me/.cache/pacaur/caddy/src/build/src/github.com/mholt/caddy/caddyhttp/httpserver/mitm.go:70 +0x6b3
net/http.serverHandler.ServeHTTP(0xc42033ca50, 0xdfdd20, 0xc420[stripped], 0xc42[stripped])
        /usr/lib/go/src/net/http/server.go:2568 +0x92
net/http.(*conn).serve(0xc420[stripped], 0xdfe8a0, 0xc42[stripped])
        /usr/lib/go/src/net/http/server.go:1825 +0x612
created by net/http.(*Server).Serve
        /usr/lib/go/src/net/http/server.go:2668 +0x2ce

Thanks! Do you happen to know the User-Agent header of those requests that cause the error? I found the problem and am adding tests but want to be sure we get it fixed. (If not, can you collect one? Just add {>User-Agent} to a log format.)

Edit: I did just reproduce the problem with my own test case but before I commit the fix I want yours just to be sure.

I’ve run into the same issue, with Gmail proxy servers being unable to access images that I am hosting from my Caddy server. Same error when they try to access my server.

I have a fix ready, but I need to be sure. Do you have a User-Agent string for me to verify my fix before I push it?

The User-Agent string contains the client system info, correct? It looks like the User-Agent string isn’t getting logged upon error. All I get is the below info:

Jul 25 10:11:00 true caddy[23784]: 2017/07/25 10:11:00 http: panic serving 66.249.84.227:57497: runtime error: slice bounds out of range
Jul 25 10:11:00 true caddy[23784]: goroutine 32 [running]:
Jul 25 10:11:00 true caddy[23784]: net/http.(*conn).serve.func1(0xc4201ddc20)
Jul 25 10:11:00 true caddy[23784]:         /usr/local/go/src/net/http/server.go:1721 +0xd0
Jul 25 10:11:00 true caddy[23784]: panic(0xa3de60, 0xe4f230)
Jul 25 10:11:00 true caddy[23784]:         /usr/local/go/src/runtime/panic.go:489 +0x2cf
Jul 25 10:11:00 true caddy[23784]: github.com/mholt/caddy/caddyhttp/httpserver.getVersion(0xc4201b92c0, 0x59, 0xaeed61, 0x7, 0x1)
Jul 25 10:11:00 true caddy[23784]:         src/github.com/mholt/caddy/caddyhttp/httpserver/mitm.go:116 +0x312
Jul 25 10:11:00 true caddy[23784]: github.com/mholt/caddy/caddyhttp/httpserver.(*tlsHandler).ServeHTTP(0xc42018e8a0, 0xdefa80, 0xc42021ba40, 0xc4201d5500)
Jul 25 10:11:00 true caddy[23784]:         src/github.com/mholt/caddy/caddyhttp/httpserver/mitm.go:70 +0x6b3
Jul 25 10:11:00 true caddy[23784]: net/http.serverHandler.ServeHTTP(0xc42005fa20, 0xdefa80, 0xc42021ba40, 0xc4201d5500)
Jul 25 10:11:00 true caddy[23784]:         /usr/local/go/src/net/http/server.go:2568 +0x92
Jul 25 10:11:00 true caddy[23784]: net/http.(*conn).serve(0xc4201ddc20, 0xdf0600, 0xc4201eabc0)
Jul 25 10:11:00 true caddy[23784]:         /usr/local/go/src/net/http/server.go:1825 +0x612
Jul 25 10:11:00 true caddy[23784]: created by net/http.(*Server).Serve
Jul 25 10:11:00 true caddy[23784]:         /usr/local/go/src/net/http/server.go:2668 +0x2ce

For reference, this is what gets logged when I access the same resource from my browser:

Jul 25 09:53:38 true caddy[23560]: [my IP addr] 25/Jul/2017:09:53:38 -0700 GET [file being accessed] HTTP/2.0 304 0 Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36

We’re looking for something like “Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36,” correct?

Yup, that’s a User Agent string. You’ll have to add {>User-Agent} to your access (and probably error) logs.

I have added {>User-Agent} to all access and error logs. There is just no line before the “runtime error” line, so a User-Agent string is not being recorded when the crash occurs. :frowning:

Well, here is my pull request: https://github.com/mholt/caddy/pull/1779

You’re welcome to build that branch and try it to see if the problem goes away! I would find the feedback valuable.

Thanks! I’ll give that a try and update here as soon as I test.

Thanks! I am too stupid to even manage to configure logging globally for my caddy proxy…

The fix worked! Thanks, Matt!

1 Like

Excellent. Merging in a moment!

@qqq No problem. :smile:

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.