mariusor / brutalinks

Link aggregator inspired by (old)reddit using ActivityPub federation. (mirror repository)
https://brutalinks.tech
MIT License
261 stars 12 forks source link

Hard crash due to logging #23

Closed mariusor closed 5 years ago

mariusor commented 5 years ago

Due to the changes of passing the request logging through our cludge log package, we missed protecting the context map with mutexes in a couple of places, which triggers some hard crashes when request concurrency is high.

Many thanx to @prismo@mastodon.social for noticing this.

fatal error: concurrent map iteration and map write

goroutine 2981 [running]:
runtime.throw(0xb11062, 0x26)
    /usr/lib/go/src/runtime/panic.go:608 +0x72 fp=0xc0004a40a8 sp=0xc0004a4078 pc=0x42c082
runtime.mapiternext(0xc0004a4178)
    /usr/lib/go/src/runtime/map.go:790 +0x525 fp=0xc0004a4130 sp=0xc0004a40a8 pc=0x40ecf5
github.com/mariusor/littr.go/internal/log.(*logger).context(0xc000ea89c0, 0x0)
    /littr.go/internal/log/logger.go:85 +0x11b fp=0xc0004a41e8 sp=0xc0004a4130 pc=0x7fb5fb
github.com/mariusor/littr.go/internal/log.logger.Debugf(0xbcc6a0, 0xc00005e180, 0xc0002f5890, 0x100000002, 0x0, 0x0, 0xaf2eb3, 0x2, 0xc000c25600, 0x1, ...)
    /littr.go/internal/log/logger.go:120 +0x71 fp=0xc0004a4260 sp=0xc0004a41e8 pc=0x7fbc91
github.com/mariusor/littr.go/internal/log.(*logger).Debugf(0xc0002f5860, 0xaf2eb3, 0x2, 0xc000c25600, 0x1, 0x1)
    <autogenerated>:1 +0x8d fp=0xc0004a42c8 sp=0xc0004a4260 pc=0x7fd87d
github.com/mariusor/littr.go/app/api.New.func2(0xc000671760, 0x2, 0x2)
    /littr.go/app/api/loader.go:42 +0x1b6 fp=0xc0004a4340 sp=0xc0004a42c8 pc=0x9a1006
github.com/go-ap/activitypub/client.client.Get(0xb264e8, 0xc0008d9740, 0x5b, 0xa0d1c0, 0xac4e01, 0xc0006e9560)
    GOPATH/share/go/pkg/mod/github.com/go-ap/activitypub@v0.0.0-20190414191238-5b5a51daed61/client/client.go:157 +0x137 fp=0xc0004a43c8 sp=0xc0004a4340 pc=0x97cb97
github.com/go-ap/activitypub/client.(*client).Get(0xc00000c908, 0xc0008d9740, 0x5b, 0x3, 0xc0006e95e8, 0xc0008d9740)
    <autogenerated>:1 +0x50 fp=0xc0004a4408 sp=0xc0004a43c8 pc=0x97d470
github.com/mariusor/littr.go/app/api.(*repository).LoadItems(0xc0002a9a00, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, ...)
    /littr.go/app/api/loader.go:597 +0x3ba fp=0xc0004a46f0 sp=0xc0004a4408 pc=0x996a7a
github.com/mariusor/littr.go/app/frontend.loadItems(0xbc4ac0, 0xc000ea8810, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, ...)
    /littr.go/app/frontend/listing.go:203 +0xfa fp=0xc0004a4c88 sp=0xc0004a46f0 pc=0x96f14a
github.com/mariusor/littr.go/app/frontend.(*handler).HandleIndex(0xc00043cf00, 0x7fc639c9f200, 0xc000ec4180, 0xc000677000)
    /littr.go/app/frontend/listing.go:179 +0x36d fp=0xc0004a5498 sp=0xc0004a4c88 pc=0x96e92d
github.com/mariusor/littr.go/app/frontend.(*handler).HandleIndex-fm(0x7fc639c9f200, 0xc000ec4180, 0xc000677000)
    /littr.go/app/frontend/routes.go:23 +0x48 fp=0xc0004a54c8 sp=0xc0004a5498 pc=0x979e08
net/http.HandlerFunc.ServeHTTP(0xc00029d710, 0x7fc639c9f200, 0xc000ec4180, 0xc000677000)
    /usr/lib/go/src/net/http/server.go:1964 +0x44 fp=0xc0004a54f0 sp=0xc0004a54c8 pc=0x766634
github.com/go-chi/chi.(*Mux).routeHTTP(0xc000410d20, 0x7fc639c9f200, 0xc000ec4180, 0xc000677000)
    GOPATH/share/go/pkg/mod/github.com/go-chi/chi@v0.0.0-20171222161133-e83ac2304db3/mux.go:424 +0x239 fp=0xc0004a5560 sp=0xc0004a54f0 pc=0x798fa9
github.com/go-chi/chi.(*Mux).routeHTTP-fm(0x7fc639c9f200, 0xc000ec4180, 0xc000677000)
    GOPATH/share/go/pkg/mod/github.com/go-chi/chi@v0.0.0-20171222161133-e83ac2304db3/mux.go:368 +0x48 fp=0xc0004a5590 sp=0xc0004a5560 pc=0x79d6a8
net/http.HandlerFunc.ServeHTTP(0xc00029d700, 0x7fc639c9f200, 0xc000ec4180, 0xc000677000)
    /usr/lib/go/src/net/http/server.go:1964 +0x44 fp=0xc0004a55b8 sp=0xc0004a5590 pc=0x766634
github.com/go-chi/chi/middleware.RequestLogger.func1.1(0xbc4240, 0xc00091c380, 0xc000676f00)
    GOPATH/share/go/pkg/mod/github.com/go-chi/chi@v0.0.0-20171222161133-e83ac2304db3/middleware/logger.go:46 +0x1b6 fp=0xc0004a5650 sp=0xc0004a55b8 pc=0x7ed8d6
net/http.HandlerFunc.ServeHTTP(0xc0002f5a70, 0xbc4240, 0xc00091c380, 0xc000676f00)
    /usr/lib/go/src/net/http/server.go:1964 +0x44 fp=0xc0004a5678 sp=0xc0004a5650 pc=0x766634
github.com/mariusor/littr.go/app.NeedsDBBackend.func1.1(0xbc4240, 0xc00091c380, 0xc000676f00)
    /littr.go/app/app.go:383 +0x135 fp=0xc0004a56d8 sp=0xc0004a5678 pc=0x8920c5
net/http.HandlerFunc.ServeHTTP(0xc00032b8a0, 0xbc4240, 0xc00091c380, 0xc000676f00)
    /usr/lib/go/src/net/http/server.go:1964 +0x44 fp=0xc0004a5700 sp=0xc0004a56d8 pc=0x766634
github.com/mariusor/littr.go/app/frontend.(*handler).LoadSession.func1(0xbc4240, 0xc00091c380, 0xc000676f00)
    /littr.go/app/frontend/frontend.go:750 +0x141 fp=0xc0004a5868 sp=0xc0004a5700 pc=0x975ac1
net/http.HandlerFunc.ServeHTTP(0xc00032b8c0, 0xbc4240, 0xc00091c380, 0xc000676f00)
    /usr/lib/go/src/net/http/server.go:1964 +0x44 fp=0xc0004a5890 sp=0xc0004a5868 pc=0x766634
github.com/go-chi/chi/middleware.GetHead.func1(0xbc4240, 0xc00091c380, 0xc000676f00)
    GOPATH/share/go/pkg/mod/github.com/go-chi/chi@v0.0.0-20171222161133-e83ac2304db3/middleware/get_head.go:37 +0x14a fp=0xc0004a5900 sp=0xc0004a5890 pc=0x7ed57a
net/http.HandlerFunc.ServeHTTP(0xc00032b8e0, 0xbc4240, 0xc00091c380, 0xc000676f00)
    /usr/lib/go/src/net/http/server.go:1964 +0x44 fp=0xc0004a5928 sp=0xc0004a5900 pc=0x766634
github.com/go-chi/chi.(*Mux).ServeHTTP(0xc000410d20, 0xbc4240, 0xc00091c380, 0xc000676f00)
    GOPATH/share/go/pkg/mod/github.com/go-chi/chi@v0.0.0-20171222161133-e83ac2304db3/mux.go:69 +0x44f fp=0xc0004a59a0 sp=0xc0004a5928 pc=0x79709f
github.com/go-chi/chi.(*Mux).Mount.func1(0xbc4240, 0xc00091c380, 0xc000676f00)
    GOPATH/share/go/pkg/mod/github.com/go-chi/chi@v0.0.0-20171222161133-e83ac2304db3/mux.go:291 +0xf5 fp=0xc0004a5a00 sp=0xc0004a59a0 pc=0x79cba5
net/http.HandlerFunc.ServeHTTP(0xc0004de820, 0xbc4240, 0xc00091c380, 0xc000676f00)
    /usr/lib/go/src/net/http/server.go:1964 +0x44 fp=0xc0004a5a28 sp=0xc0004a5a00 pc=0x766634
github.com/mariusor/littr.go/app/api.handler.Repository.func1(0xbc4240, 0xc00091c380, 0xc000676e00)
    /littr.go/app/api/loader.go:132 +0x18f fp=0xc0004a5ac0 sp=0xc0004a5a28 pc=0x9a11ef
net/http.HandlerFunc.ServeHTTP(0xc0000a1900, 0xbc4240, 0xc00091c380, 0xc000676e00)
    /usr/lib/go/src/net/http/server.go:1964 +0x44 fp=0xc0004a5ae8 sp=0xc0004a5ac0 pc=0x766634
github.com/go-chi/chi.(*ChainHandler).ServeHTTP(0xc0000a1940, 0xbc4240, 0xc00091c380, 0xc000676e00)
    GOPATH/share/go/pkg/mod/github.com/go-chi/chi@v0.0.0-20171222161133-e83ac2304db3/chain.go:31 +0x52 fp=0xc0004a5b18 sp=0xc0004a5ae8 pc=0x7963a2
github.com/go-chi/chi.(*Mux).routeHTTP(0xc000410c60, 0xbc4240, 0xc00091c380, 0xc000676e00)
    GOPATH/share/go/pkg/mod/github.com/go-chi/chi@v0.0.0-20171222161133-e83ac2304db3/mux.go:424 +0x239 fp=0xc0004a5b88 sp=0xc0004a5b18 pc=0x798fa9
github.com/go-chi/chi.(*Mux).routeHTTP-fm(0xbc4240, 0xc00091c380, 0xc000676e00)
    GOPATH/share/go/pkg/mod/github.com/go-chi/chi@v0.0.0-20171222161133-e83ac2304db3/mux.go:368 +0x48 fp=0xc0004a5bb8 sp=0xc0004a5b88 pc=0x79d6a8
net/http.HandlerFunc.ServeHTTP(0xc00029d690, 0xbc4240, 0xc00091c380, 0xc000676e00)
    /usr/lib/go/src/net/http/server.go:1964 +0x44 fp=0xc0004a5be0 sp=0xc0004a5bb8 pc=0x766634
github.com/go-chi/chi/middleware.RequestID.func1(0xbc4240, 0xc00091c380, 0xc000676d00)
    GOPATH/share/go/pkg/mod/github.com/go-chi/chi@v0.0.0-20171222161133-e83ac2304db3/middleware/request_id.go:68 +0x285 fp=0xc0004a5ca8 sp=0xc0004a5be0 pc=0x7edf15
net/http.HandlerFunc.ServeHTTP(0xc00032b820, 0xbc4240, 0xc00091c380, 0xc000676d00)
    /usr/lib/go/src/net/http/server.go:1964 +0x44 fp=0xc0004a5cd0 sp=0xc0004a5ca8 pc=0x766634
github.com/go-chi/chi.(*Mux).ServeHTTP(0xc000410c60, 0xbc4240, 0xc00091c380, 0xc000676c00)
    GOPATH/share/go/pkg/mod/github.com/go-chi/chi@v0.0.0-20171222161133-e83ac2304db3/mux.go:81 +0x293 fp=0xc0004a5d48 sp=0xc0004a5cd0 pc=0x796ee3
net/http.serverHandler.ServeHTTP(0xc000073450, 0xbc4240, 0xc00091c380, 0xc000676c00)
    /usr/lib/go/src/net/http/server.go:2741 +0xab fp=0xc0004a5d78 sp=0xc0004a5d48 pc=0x76928b
net/http.(*conn).serve(0xc0001fe1e0, 0xbc4a00, 0xc000ec4080)
    /usr/lib/go/src/net/http/server.go:1847 +0x646 fp=0xc0004a5fc8 sp=0xc0004a5d78 pc=0x765696
runtime.goexit()
    /usr/lib/go/src/runtime/asm_amd64.s:1333 +0x1 fp=0xc0004a5fd0 sp=0xc0004a5fc8 pc=0x45bac1
created by net/http.(*Server).Serve
    /usr/lib/go/src/net/http/server.go:2851 +0x2f5
mariusor commented 5 years ago

Fixed in d3f514a79b679b884.