diff --git a/dot/rpc/subscription/listeners_test.go b/dot/rpc/subscription/listeners_test.go index 13a20914bc..3c6375259b 100644 --- a/dot/rpc/subscription/listeners_test.go +++ b/dot/rpc/subscription/listeners_test.go @@ -121,8 +121,8 @@ func TestBlockFinalizedListener_Listen(t *testing.T) { } func TestExtrinsicSubmitListener_Listen(t *testing.T) { - notifyImportedChan := make(chan *types.Block) - notifyFinalizedChan := make(chan *types.FinalisationInfo) + notifyImportedChan := make(chan *types.Block, 100) + notifyFinalizedChan := make(chan *types.FinalisationInfo, 100) mockConnection := &MockWSConnAPI{} esl := ExtrinsicSubmitListener{ diff --git a/dot/rpc/subscription/websocket.go b/dot/rpc/subscription/websocket.go index e36bed8795..816032ae27 100644 --- a/dot/rpc/subscription/websocket.go +++ b/dot/rpc/subscription/websocket.go @@ -43,6 +43,9 @@ var errCannotReadFromWebsocket = errors.New("cannot read message from websocket" var errCannotUnmarshalMessage = errors.New("cannot unmarshal webasocket message data") var logger = log.New("pkg", "rpc/subscription") +// DEFAULT_BUFFER_SIZE buffer size for channels +const DEFAULT_BUFFER_SIZE = 100 + // WSConn struct to hold WebSocket Connection references type WSConn struct { Wsconn *websocket.Conn @@ -228,7 +231,7 @@ func (c *WSConn) unsubscribeStorageListener(reqID float64, l Listener, _ interfa func (c *WSConn) initBlockListener(reqID float64, _ interface{}) (Listener, error) { bl := &BlockListener{ - Channel: make(chan *types.Block), + Channel: make(chan *types.Block, DEFAULT_BUFFER_SIZE), wsconn: c, } @@ -260,7 +263,7 @@ func (c *WSConn) initBlockListener(reqID float64, _ interface{}) (Listener, erro func (c *WSConn) initBlockFinalizedListener(reqID float64, _ interface{}) (Listener, error) { bfl := &BlockFinalizedListener{ - channel: make(chan *types.FinalisationInfo), + channel: make(chan *types.FinalisationInfo, DEFAULT_BUFFER_SIZE), wsconn: c, } @@ -299,10 +302,10 @@ func (c *WSConn) initExtrinsicWatch(reqID float64, params interface{}) (Listener // listen for built blocks esl := &ExtrinsicSubmitListener{ - importedChan: make(chan *types.Block), + importedChan: make(chan *types.Block, DEFAULT_BUFFER_SIZE), wsconn: c, extrinsic: types.Extrinsic(extBytes), - finalisedChan: make(chan *types.FinalisationInfo), + finalisedChan: make(chan *types.FinalisationInfo, DEFAULT_BUFFER_SIZE), } if c.BlockAPI == nil {