mediachain / concat

Mediachain daemons
MIT License
42 stars 13 forks source link

crash when adding authorization #93

Closed yusefnapora closed 7 years ago

yusefnapora commented 7 years ago

I got a crash in mcnode trying to add an authorization for another local testing node:

$ mcclient --apiUrl http://localhost:9004 auth grant QmXY1nyb6sbXgdAjEjDHcqXfpmmwjhj3S1KPSu94grp1xo 'museums.tate.*'
request to http://localhost:9004/auth/QmXY1nyb6sbXgdAjEjDHcqXfpmmwjhj3S1KPSu94grp1xo failed, reason: socket hang up

The node's log:

2016/12/05 17:23:05 http: panic serving 127.0.0.1:51766: assignment to entry in nil map
goroutine 34 [running]:
net/http.(*conn).serve.func1(0xc420092d00)
    /usr/local/go/src/net/http/server.go:1491 +0x12a
panic(0x49200e0, 0xc42048dcb0)
    /usr/local/go/src/runtime/panic.go:458 +0x243
main.(*PeerAuth).setRules(0xc420414460, 0xc4204229c0, 0x22, 0xc42048dca0, 0x1, 0x1)
    /Users/yusef/go/src/github.com/mediachain/concat/mcnode/node.go:454 +0xa3
main.(*Node).httpAuthPeerSet(0xc420414360, 0x4ce2a80, 0xc4200769c0, 0xc4200d0a50)
    /Users/yusef/go/src/github.com/mediachain/concat/mcnode/api.go:923 +0x3da
main.(*Node).(main.httpAuthPeerSet)-fm(0x4ce2a80, 0xc4200769c0, 0xc4200d0a50)
    /Users/yusef/go/src/github.com/mediachain/concat/mcnode/api.go:883 +0x48
main.apiConfigMethod(0x4ce2a80, 0xc4200769c0, 0xc4200d0a50, 0xc420045b78, 0xc420045b68)
    /Users/yusef/go/src/github.com/mediachain/concat/mcnode/api.go:754 +0xea
main.(*Node).httpAuthPeer(0xc420414360, 0x4ce2a80, 0xc4200769c0, 0xc4200d0a50)
    /Users/yusef/go/src/github.com/mediachain/concat/mcnode/api.go:883 +0x7a
main.(*Node).(main.httpAuthPeer)-fm(0x4ce2a80, 0xc4200769c0, 0xc4200d0a50)
    /Users/yusef/go/src/github.com/mediachain/concat/mcnode/main.go:97 +0x48
net/http.HandlerFunc.ServeHTTP(0xc42048cd20, 0x4ce2a80, 0xc4200769c0, 0xc4200d0a50)
    /usr/local/go/src/net/http/server.go:1726 +0x44
github.com/gorilla/mux.(*Router).ServeHTTP(0xc420418500, 0x4ce2a80, 0xc4200769c0, 0xc4200d0a50)
    /Users/yusef/go/src/github.com/gorilla/mux/mux.go:114 +0x10d
net/http.serverHandler.ServeHTTP(0xc420092a80, 0x4ce2a80, 0xc4200769c0, 0xc4200d0870)
    /usr/local/go/src/net/http/server.go:2202 +0x7d
net/http.(*conn).serve(0xc420092d00, 0x4ce3240, 0xc4200e9640)
    /usr/local/go/src/net/http/server.go:1579 +0x4b7
created by net/http.(*Server).Serve
    /usr/local/go/src/net/http/server.go:2293 +0x44d

after the crash, I could still get the node's id:

$ mcclient --apiUrl http://localhost:9004 id
Peer ID: QmPMkbeHUB3jmnax3VZXgoRJXY49NUCUX2bTboNTA57QMK
Publisher ID: 4XTTM4CEhhA1MDfXhXVJeyzcHPFRGnAf8iAiVHDSpgUGViyFJ
Info:

But auth commands time out:

$ mcclient --apiUrl http://localhost:9004 auth show
network timeout at: http://localhost:9004/auth

I think this is happening because the auth.peers map is only created in the fromJSON method, so if the node doesn't have a config file, that method is never called and the auth map is nil.

Adding this config file to the node's data dir fixes it:

{"nat":"none","auth":{}}

Or, if you set any other config that causes the file to be created, e.g. mcclient config nat auto, then restart the node, it will trigger that method and create the map.

parkan commented 7 years ago

Nice investigative work :+1:

vyzo commented 7 years ago

Oops, I really didn't check without a config.