[#1170] pkg/morph: Add worker pool

Add worker pool to the listener to prevent blocking. It is used only for
notary notifications and new block events handling since it uses RPC
calls. That may lead to the deadlock state: neo-go cannot send RPC until
notification channel is read but notification channel cannot be read since
neo-go client cannot send RPC.

Signed-off-by: Pavel Karpy <carpawell@nspcc.ru>
This commit is contained in:
Pavel Karpy 2022-04-01 17:18:14 +03:00 committed by Alex Vanin
parent 4ed5b1ceef
commit 01e69f2f7a
3 changed files with 56 additions and 7 deletions

View file

@ -173,6 +173,14 @@ func waitNotaryDeposit(c *cfg, tx util.Uint256) error {
}
func listenMorphNotifications(c *cfg) {
// listenerPoolCap is a capacity of a
// worker pool inside the listener. It
// is used to prevent blocking in neo-go:
// the client cannot make RPC requests if
// the notification channel is not being
// read by another goroutine.
const listenerPoolCap = 10
var (
err error
subs subscriber.Subscriber
@ -192,8 +200,9 @@ func listenMorphNotifications(c *cfg) {
fatalOnErr(err)
lis, err := event.NewListener(event.ListenerParams{
Logger: c.log,
Subscriber: subs,
Logger: c.log,
Subscriber: subs,
WorkerPoolCapacity: listenerPoolCap,
})
fatalOnErr(err)