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

Panic on bad path via API #4461

Closed
Stebalien opened this issue Dec 6, 2017 · 3 comments · Fixed by #5653
Closed

Panic on bad path via API #4461

Stebalien opened this issue Dec 6, 2017 · 3 comments · Fixed by #5653
Assignees
Labels
kind/bug A bug in existing code (including security flaws)

Comments

@Stebalien
Copy link
Member

I'm seeing the following error (produced by the daemon) when manually calling the API with a bad path (and asking for a protobuf output):

> curl -i "http://localhost:5001/api/v0/object/get?arg=&encoding=protobuf"
20:37:12.107 ERROR  cmds/http: expected type <-chan interface {}, got <nil> responseemitter.go:124
20:37:12.107 ERROR  cmds/http: a panic has occurred in the commands handler! handler.go:125
20:37:12.107 ERROR  cmds/http: expected type <-chan interface {}, got <nil> handler.go:126
20:37:12.108 ERROR  cmds/http: stack trace:
goroutine 929199 [running]:
runtime/debug.Stack(0xc42000d520, 0xc42e61f890, 0x1)
        /usr/lib/go/src/runtime/debug/stack.go:24 +0xa7
gx/ipfs/QmamUWYjFeYYzFDFPTvnmGkozJigsoDWUA4zoifTRFTnwK/go-ipfs-cmds/http.internalHandler.ServeHTTP.func1()
        /home/steb/projects/go/src/gx/ipfs/QmamUWYjFeYYzFDFPTvnmGkozJigsoDWUA4zoifTRFTnwK/go-ipfs-cmds/http/handler.go:127 +0x130
panic(0x12cd260, 0xc42e61f430)
        /usr/lib/go/src/runtime/panic.go:491 +0x283
gx/ipfs/QmamUWYjFeYYzFDFPTvnmGkozJigsoDWUA4zoifTRFTnwK/go-ipfs-cmds/http.(*responseEmitter).SetError(0xc4202a9880, 0x12cd260, 0xc420073960, 0x0)
        /home/steb/projects/go/src/gx/ipfs/QmamUWYjFeYYzFDFPTvnmGkozJigsoDWUA4zoifTRFTnwK/go-ipfs-cmds/http/responseemitter.go:147 +0x228
gx/ipfs/QmamUWYjFeYYzFDFPTvnmGkozJigsoDWUA4zoifTRFTnwK/go-ipfs-cmds.(*fakeResponse).SetError(0xc423edadc0, 0x1cb3280, 0xc420073960, 0x0)
        /home/steb/projects/go/src/gx/ipfs/QmamUWYjFeYYzFDFPTvnmGkozJigsoDWUA4zoifTRFTnwK/go-ipfs-cmds/legacy.go:191 +0xa6
github.com/ipfs/go-ipfs/core/commands/object.glob..func4(0x1cc95c0, 0xc42e61f0e0, 0x1cc8620, 0xc423edadc0)
        /home/steb/projects/go/src/github.com/ipfs/go-ipfs/core/commands/object/object.go:221 +0x517
gx/ipfs/QmamUWYjFeYYzFDFPTvnmGkozJigsoDWUA4zoifTRFTnwK/go-ipfs-cmds.NewCommand.func1(0x1cc9500, 0xc421992480, 0x6723494dcd68, 0xc4202a9880)
        /home/steb/projects/go/src/gx/ipfs/QmamUWYjFeYYzFDFPTvnmGkozJigsoDWUA4zoifTRFTnwK/go-ipfs-cmds/legacy.go:405 +0x18c
gx/ipfs/QmamUWYjFeYYzFDFPTvnmGkozJigsoDWUA4zoifTRFTnwK/go-ipfs-cmds.(*Command).Call(0x1c98660, 0x1cc9500, 0xc421992480, 0x6723494dcd68, 0xc4202a9880, 0x0, 0x0)
        /home/steb/projects/go/src/gx/ipfs/QmamUWYjFeYYzFDFPTvnmGkozJigsoDWUA4zoifTRFTnwK/go-ipfs-cmds/command.go:118 +0x1cb
gx/ipfs/QmamUWYjFeYYzFDFPTvnmGkozJigsoDWUA4zoifTRFTnwK/go-ipfs-cmds/http.internalHandler.ServeHTTP(0x0, 0xc42001804a, 0xd, 0xc42027ea80, 0xc4201cc240, 0x1573708, 0xc4201be700, 0xc420382fa0, 0x1c98660, 0xc42027e5a0, ...)
        /home/steb/projects/go/src/gx/ipfs/QmamUWYjFeYYzFDFPTvnmGkozJigsoDWUA4zoifTRFTnwK/go-ipfs-cmds/http/handler.go:193 +0x9c3
gx/ipfs/QmamUWYjFeYYzFDFPTvnmGkozJigsoDWUA4zoifTRFTnwK/go-ipfs-cmds/http.(*internalHandler).ServeHTTP(0xc4204f3b80, 0x1cbdb00, 0xc4204f8358, 0xc420356100)
        <autogenerated>:1 +0x72
gx/ipfs/QmPG2kW5t27LuHgHnvhUwbHCNHAt2eUcb4gPHqofrESUdB/cors.(*Cors).Handler.func1(0x1cbdb00, 0xc4204f8358, 0xc420356100)
        /home/steb/projects/go/src/gx/ipfs/QmPG2kW5t27LuHgHnvhUwbHCNHAt2eUcb4gPHqofrESUdB/cors/cors.go:188 +0x108
net/http.HandlerFunc.ServeHTTP(0xc4202c4c00, 0x1cbdb00, 0xc4204f8358, 0xc420356100)
        /usr/lib/go/src/net/http/server.go:1918 +0x44
gx/ipfs/QmamUWYjFeYYzFDFPTvnmGkozJigsoDWUA4zoifTRFTnwK/go-ipfs-cmds/http.Handler.ServeHTTP(0x0, 0xc42001804a, 0xd, 0xc42027ea80, 0xc4201cc240, 0x1573708, 0x0, 0xc420382fa0, 0x1c98660, 0xc42027e5a0, ...)
        /home/steb/projects/go/src/gx/ipfs/QmamUWYjFeYYzFDFPTvnmGkozJigsoDWUA4zoifTRFTnwK/go-ipfs-cmds/http/handler.go:117 +0x5e
gx/ipfs/QmamUWYjFeYYzFDFPTvnmGkozJigsoDWUA4zoifTRFTnwK/go-ipfs-cmds/http.(*Handler).ServeHTTP(0xc420287ec0, 0x1cbdb00, 0xc4204f8358, 0xc420356100)
        <autogenerated>:1 +0x78
net/http.(*ServeMux).ServeHTTP(0xc420311800, 0x1cbdb00, 0xc4204f8358, 0xc420356100)
        /usr/lib/go/src/net/http/server.go:2254 +0x130
net/http.(Handler).ServeHTTP-fm(0x1cbdb00, 0xc4204f8358, 0xc420356100)
        /usr/lib/go/src/net/http/h2_bundle.go:5462 +0x4d
gx/ipfs/QmX3QZ5jHEPidwUrymXV1iSCSUhdGxj15sm2gP4jKMef7B/client_golang/prometheus.InstrumentHandlerFuncWithOpts.func1(0x1cbf080, 0xc42dc761c0, 0xc420356100)
        /home/steb/projects/go/src/gx/ipfs/QmX3QZ5jHEPidwUrymXV1iSCSUhdGxj15sm2gP4jKMef7B/client_golang/prometheus/http.go:287 +0x26f
net/http.HandlerFunc.ServeHTTP(0xc4204f32c0, 0x1cbf080, 0xc42dc761c0, 0xc420356100)
        /usr/lib/go/src/net/http/server.go:1918 +0x44
net/http.(*ServeMux).ServeHTTP(0xc4203117d0, 0x1cbf080, 0xc42dc761c0, 0xc420356100)
        /usr/lib/go/src/net/http/server.go:2254 +0x130
net/http.serverHandler.ServeHTTP(0xc4201b1520, 0x1cbf080, 0xc42dc761c0, 0xc420356100)
        /usr/lib/go/src/net/http/server.go:2619 +0xb4
net/http.(*conn).serve(0xc4285f6320, 0x1cbff00, 0xc4213c7740)
        /usr/lib/go/src/net/http/server.go:1801 +0x71d
created by net/http.(*Server).Serve
        /usr/lib/go/src/net/http/server.go:2720 +0x288
 handler.go:127

related to #2468

This is not fixed by ipfs/go-ipfs-cmds#34

@Stebalien Stebalien added the kind/bug A bug in existing code (including security flaws) label Dec 6, 2017
@Stebalien Stebalien changed the title Panic on pad path via API Panic on bad path via API Dec 13, 2017
@keks
Copy link
Contributor

keks commented Dec 15, 2017

The problem here is that an error occurs and we can't encode that error using protobuf. When the error occurs we call SetError (at core/commands/object/object.go:221), which calls Emit, which tries to encode the error and fails with an uninformative error. SetError panics if Emit fails, which is what we see here.
I have some local changes that make the error more informative, but I'm not sure how we can keep complexity in bounds and not panic in the handler.

Digging through this made me wonder what happened before go-ipfs-cmds. Here is the output for 0.4.13:

15:47:55.443 ERROR commands/h: a panic has occurred in the commands handler! handler.go:124
15:47:55.444 ERROR commands/h: interface conversion: interface {} is nil, not *objectcmd.Node handler.go:125
goroutine 130 [running]:
runtime/debug.Stack(0x3e, 0xc4202854a0, 0xd23d3a)
	/home/keks/local/go/src/runtime/debug/stack.go:24 +0xa7
runtime/debug.PrintStack()
	/home/keks/local/go/src/runtime/debug/stack.go:16 +0x22
github.com/ipfs/go-ipfs/commands/http.internalHandler.ServeHTTP.func1()
	/home/keks/gopaths/ipfs/src/github.com/ipfs/go-ipfs/commands/http/handler.go:127 +0x129
panic(0x12b4c20, 0xc420dea280)
	/home/keks/local/go/src/runtime/panic.go:491 +0x283
github.com/ipfs/go-ipfs/core/commands/object.glob..func5(0x1c749c0, 0xc4205001c0, 0xc42001c0a5, 0x8, 0xc420198be8, 0xc42001c0a5)
	/home/keks/gopaths/ipfs/src/github.com/ipfs/go-ipfs/core/commands/object/object.go:238 +0x1cc
github.com/ipfs/go-ipfs/commands.(*response).Marshal(0xc4205001c0, 0x0, 0x0, 0x0, 0x0)
	/home/keks/gopaths/ipfs/src/github.com/ipfs/go-ipfs/commands/response.go:194 +0x16a
github.com/ipfs/go-ipfs/commands.(*response).Reader(0xc4205001c0, 0xc420dee0a0, 0x13d83e9, 0x14, 0x0)
	/home/keks/gopaths/ipfs/src/github.com/ipfs/go-ipfs/commands/response.go:214 +0xd5
github.com/ipfs/go-ipfs/commands/http.sendResponse(0x1c6a140, 0xc420de2008, 0xc420df4000, 0x1c749c0, 0xc4205001c0, 0x1c75740, 0xc420dfe180)
	/home/keks/gopaths/ipfs/src/github.com/ipfs/go-ipfs/commands/http/handler.go:235 +0x125
github.com/ipfs/go-ipfs/commands/http.internalHandler.ServeHTTP(0x0, 0xc420092b10, 0x10, 0xc420202ab0, 0xc420266000, 0x1534b68, 0xc42014a1c0, 0xc4204fcc40, 0x1c41160, 0xc4202029c0, ...)
	/home/keks/gopaths/ipfs/src/github.com/ipfs/go-ipfs/commands/http/handler.go:193 +0x96c
github.com/ipfs/go-ipfs/commands/http.(*internalHandler).ServeHTTP(0xc420dc2190, 0x1c6a140, 0xc420de2008, 0xc420df4000)
	<autogenerated>:1 +0x72
gx/ipfs/QmPG2kW5t27LuHgHnvhUwbHCNHAt2eUcb4gPHqofrESUdB/cors.(*Cors).Handler.func1(0x1c6a140, 0xc420de2008, 0xc420df4000)
	/home/keks/gopaths/ipfs/src/gx/ipfs/QmPG2kW5t27LuHgHnvhUwbHCNHAt2eUcb4gPHqofrESUdB/cors/cors.go:188 +0x108
net/http.HandlerFunc.ServeHTTP(0xc420206460, 0x1c6a140, 0xc420de2008, 0xc420df4000)
	/home/keks/local/go/src/net/http/server.go:1918 +0x44
github.com/ipfs/go-ipfs/commands/http.Handler.ServeHTTP(0x0, 0xc420092b10, 0x10, 0xc420202ab0, 0xc420266000, 0x1534b68, 0x0, 0xc4204fcc40, 0x1c41160, 0xc4202029c0, ...)
	/home/keks/gopaths/ipfs/src/github.com/ipfs/go-ipfs/commands/http/handler.go:116 +0x5e
github.com/ipfs/go-ipfs/commands/http.(*Handler).ServeHTTP(0xc4201605a0, 0x1c6a140, 0xc420de2008, 0xc420df4000)
	<autogenerated>:1 +0x78
net/http.(*ServeMux).ServeHTTP(0xc420202030, 0x1c6a140, 0xc420de2008, 0xc420df4000)
	/home/keks/local/go/src/net/http/server.go:2254 +0x130
net/http.(Handler).ServeHTTP-fm(0x1c6a140, 0xc420de2008, 0xc420df4000)
	/home/keks/local/go/src/net/http/h2_bundle.go:5462 +0x4d
gx/ipfs/QmX3QZ5jHEPidwUrymXV1iSCSUhdGxj15sm2gP4jKMef7B/client_golang/prometheus.InstrumentHandlerFuncWithOpts.func1(0x1c6b700, 0xc4205260e0, 0xc420df4000)
	/home/keks/gopaths/ipfs/src/gx/ipfs/QmX3QZ5jHEPidwUrymXV1iSCSUhdGxj15sm2gP4jKMef7B/client_golang/prometheus/http.go:287 +0x26f
net/http.HandlerFunc.ServeHTTP(0xc420dc2140, 0x1c6b700, 0xc4205260e0, 0xc420df4000)
	/home/keks/local/go/src/net/http/server.go:1918 +0x44
net/http.(*ServeMux).ServeHTTP(0xc420202000, 0x1c6b700, 0xc4205260e0, 0xc420df4000)
	/home/keks/local/go/src/net/http/server.go:2254 +0x130
net/http.serverHandler.ServeHTTP(0xc420dda000, 0x1c6b700, 0xc4205260e0, 0xc420df4000)
	/home/keks/local/go/src/net/http/server.go:2619 +0xb4
net/http.(*conn).serve(0xc4205020a0, 0x1c6c580, 0xc420dea040)
	/home/keks/local/go/src/net/http/server.go:1801 +0x71d
created by net/http.(*Server).Serve
	/home/keks/local/go/src/net/http/server.go:2720 +0x288

@keks
Copy link
Contributor

keks commented Dec 15, 2017

Branch with more informative error: https://github.com/ipfs/go-ipfs-cmds/tree/fix/cant-encode-error

@Stebalien
Copy link
Member Author

Oh. THIS bug. #2517

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug A bug in existing code (including security flaws)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants