resgateio / resgate

A Realtime API Gateway used with NATS to build REST, real time, and RPC APIs, where all your clients are synchronized seamlessly.
https://resgate.io
MIT License
689 stars 67 forks source link

Crash on timed out resources #86

Closed jirenius closed 5 years ago

jirenius commented 5 years ago

Issue

Resources that time out causes Resgate to crash.

Log

13:23:35 [Main] Starting server
13:23:35 [Main] Connecting to messaging system
13:23:35 [Main] Starting HTTP server
13:23:35 [Main] Listening on http://0.0.0.0:8080
13:23:39 [bj5d6et8smghhs6or5ng] Connected
13:23:39 [bj5d6et8smghhs6or5ng] --> {"id":15,"method":"subscribe.viewerService.collection"}
13:23:39 [NATS] <== access.viewerService.collection: {"token":null,"cid":"bj5d6et8smghhs6or5ng"}
13:23:39 [NATS] <== get.viewerService.collection: {}
13:23:41 [NATS] x=> Request timeout
13:23:41 [bj5d6et8smghhs6or5ng] <-- {"error":{"code":"system.timeout","message":"Request timeout"},"id":15}
13:23:41 [NATS] x=> Request timeout
panic: runtime error: invalid memory address or nil pointer dereference
[signal 0xc0000005 code=0x0 addr=0x0 pc=0x69b8fb]

goroutine 50 [running]:
github.com/jirenius/resgate/server/rescache.(*ResourceSubscription).Unsubscribe(0x0, 0x7d7ec0, 0xc0001b6000)
        C:/dev/go/src/github.com/jirenius/resgate/server/rescache/resourceSubscription.go:119 +0x6b
github.com/jirenius/resgate/server.(*Subscription).Loaded.func1()
        C:/dev/go/src/github.com/jirenius/resgate/server/subscription.go:144 +0x16b
github.com/jirenius/resgate/server.(*wsConn).outputWorker(0xc0001a0000)
        C:/dev/go/src/github.com/jirenius/resgate/server/wsConn.go:531 +0x64
created by github.com/jirenius/resgate/server.(*Service).newWSConn
        C:/dev/go/src/github.com/jirenius/resgate/server/wsConn.go:66 +0x301

Note

Bug was introduced in #84

jirenius commented 5 years ago

Bug was not caught by tests as it only occurred in the resource was disposed prior to the timeout response.

Since the tests mock a timeout, instead of waiting, the resource was never disposed.

jirenius commented 5 years ago

Solved in #87