jcelliott / turnpike

Go implementation of a WAMP (Web Application Messaging Protocol) client and router
MIT License
258 stars 88 forks source link

Client panics when connection is closed while `waitForListener` is waiting for message #148

Closed robert-jackson-spirent closed 3 years ago

robert-jackson-spirent commented 3 years ago

Encountered a panic in the client when a subscribe message is sent and the connection is immediately closed (logs included below). The waitForListener function will eventually timeout but when it does an attempt to write to the acts channel which has already closed produces the panic. The fix is to close all listener channels before exiting main run() loop which allows waitForListener to determine the listener channel has closed and return w/o writing acts.

NOTE: Also includes govendor update github.com/jtolds/gls as unit tests panic w/o this (using go 1.14)

time="2021-06-28T15:32:39Z" level=debug msg=close realm=test router="{ws   1.1.1.1 /api/ws  false  }"
time="2021-06-28T15:32:42Z" level=error msg="websocket: bad handshake" realm=test router="{ws   1.1.1.1 /api/ws  false  }"
time="2021-06-28T15:32:59Z" level=debug msg=open realm=test router="{ws   1.1.1.1 /api/ws  false  }"
time="2021-06-28T15:32:59Z" level=info msg=connected realm=test router="{ws   1.1.1.1 /api/ws  false  }"
time="2021-06-28T15:33:09Z" level=error msg="timeout while waiting for message" realm=test router="{ws   1.1.1.1 /api/ws  false  }" topic=orion.admin.user.events.v1
time="2021-06-28T15:33:09Z" level=debug msg=close realm=test router="{ws   1.1.1.1 /api/ws  false  }"
time="2021-06-28T15:33:10Z" level=debug msg=open realm=test router="{ws   1.1.1.1 /api/ws  false  }"
time="2021-06-28T15:33:10Z" level=info msg=connected realm=test router="{ws   1.1.1.1 /api/ws  false  }"
time="2021-06-28T15:33:20Z" level=debug msg=close realm=test router="{ws   1.1.1.1 /api/ws  false  }"
panic: send on closed channel