thrasher-corp / gocryptotrader

A cryptocurrency trading bot and framework supporting multiple exchanges written in Golang.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Dispatcher tries to return used channels that are `<-chan interface{}` as `chan interface` and fails

TaltaM opened this issue · comments

commented

New Issue

Context

Expected Behavior

Tickers, orderbooks and balance data can be accessed through a subscription using a multiplexer using the dispatch package.
Subscribing to a UUID of a ticker/orderbook/account provides a 'Pipe' that holds a channel which is provided through sync.Pool. When unsubscribing from the item's updates through releasing the pipe, the used channel is returned to the pool. On a subsequent subscription, Pool.Get() doesn't return a New() item, but it pops a used channel and returns it to the caller.

Current Behavior

Currently, when unsubscribing, a <-chan interface{} is put into the Pool, while subscribing tries to get a chan interface{}. As the pool holds used items as any types, a type assertion error is produced when accessing a used channel of type <-chan interface{} as a chan interface{} in dispatch/dispatch.go:245

	ch, ok := getResult.(chan interface{})
	if !ok {
		return nil, errTypeAssertionFailure
	}

Failure Information (for bugs)

Steps to Reproduce

To reproduce, subscribe, unsubscribe and subscribe as per this (updated) test:

TaltaM@387fca9

$ go test -v ./dispatch
=== RUN   TestGlobalDispatcher
--- PASS: TestGlobalDispatcher (0.00s)
<...snap...>
=== CONT  TestSubscribe
=== NAME  TestUnsubscribe
    dispatch_test.go:229: received: 'type assertion failure - <-chan interface {} is not a chan interface {}' but expected: '<nil>'
--- FAIL: TestUnsubscribe (0.00s)
<...snap...>