Skip to content

Commit 402204a

Browse files
committed
meta: fix container creation deadlock
It is prohibited to make RPC calls if you are not reading notification channel. If last container removal and new container creation are events from a single block, 7ec47bd deadlocks in its (re)subscription subroutines. The logic will be improved in the future when every notification is handled in a strict order: #3259. Signed-off-by: Pavel Karpy <[email protected]>
1 parent 15ce1f8 commit 402204a

File tree

2 files changed

+13
-8
lines changed

2 files changed

+13
-8
lines changed

pkg/services/meta/meta.go

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@ const (
2626
// rootKey is the key for the last known state root in KV data base
2727
// associated with MPT.
2828
rootKey = 0x00
29+
30+
// notificationBuffSize is a nesessary buffer for neo-go's client proper
31+
// notification work; it is required to always read notifications without
32+
// any blocking or making additional RPC
33+
notificationBuffSize = 100
2934
)
3035

3136
// NeoFSNetwork describes current NeoFS storage network state.
@@ -200,10 +205,10 @@ func New(p Parameters) (*Meta, error) {
200205
net: p.Network,
201206
endpoints: p.NeoEnpoints,
202207
timeout: p.Timeout,
203-
bCh: make(chan *block.Header),
204-
cnrDelEv: make(chan *state.ContainedNotificationEvent),
205-
cnrPutEv: make(chan *state.ContainedNotificationEvent),
206-
epochEv: make(chan *state.ContainedNotificationEvent),
208+
bCh: make(chan *block.Header, notificationBuffSize),
209+
cnrDelEv: make(chan *state.ContainedNotificationEvent, notificationBuffSize),
210+
cnrPutEv: make(chan *state.ContainedNotificationEvent, notificationBuffSize),
211+
epochEv: make(chan *state.ContainedNotificationEvent, notificationBuffSize),
207212
blockBuff: make(chan *block.Header, blockBuffSize),
208213
storages: storages}, nil
209214
}

pkg/services/meta/notifications.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ func (m *Meta) reconnect(ctx context.Context) error {
197197

198198
m.stM.RLock()
199199
if len(m.storages) > 0 {
200-
m.bCh = make(chan *block.Header)
200+
m.bCh = make(chan *block.Header, notificationBuffSize)
201201
m.blockSubID, err = m.subscribeForBlocks(m.bCh)
202202
if err != nil {
203203
m.stM.RUnlock()
@@ -206,9 +206,9 @@ func (m *Meta) reconnect(ctx context.Context) error {
206206
}
207207
m.stM.RUnlock()
208208

209-
m.cnrDelEv = make(chan *state.ContainedNotificationEvent)
210-
m.cnrPutEv = make(chan *state.ContainedNotificationEvent)
211-
m.epochEv = make(chan *state.ContainedNotificationEvent)
209+
m.cnrDelEv = make(chan *state.ContainedNotificationEvent, notificationBuffSize)
210+
m.cnrPutEv = make(chan *state.ContainedNotificationEvent, notificationBuffSize)
211+
m.epochEv = make(chan *state.ContainedNotificationEvent, notificationBuffSize)
212212

213213
err = m.subscribeForMeta()
214214
if err != nil {

0 commit comments

Comments
 (0)