Skip to content

Commit

Permalink
GRPC streaming move lock above send orderbook updates (#1707)
Browse files Browse the repository at this point in the history
  • Loading branch information
jonfung-dydx authored Jun 18, 2024
1 parent 357206b commit a8619a7
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions protocol/streaming/grpc/grpc_streaming_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,9 @@ func (sm *GrpcStreamingManagerImpl) SendOrderbookUpdates(
updatesByClobPairId[clobPairId] = v1updates
}

sm.Lock()
defer sm.Unlock()

updatesBySubscriptionId := make(map[uint32][]clobtypes.StreamUpdate)
for id, subscription := range sm.orderbookSubscriptions {
// Consolidate orderbook updates into a single `StreamUpdate`.
Expand Down Expand Up @@ -185,6 +188,9 @@ func (sm *GrpcStreamingManagerImpl) SendOrderbookFillUpdates(
updatesByClobPairId[clobPairId] = append(updatesByClobPairId[clobPairId], streamUpdate)
}

sm.Lock()
defer sm.Unlock()

updatesBySubscriptionId := make(map[uint32][]clobtypes.StreamUpdate)
for id, subscription := range sm.orderbookSubscriptions {
streamUpdatesForSubscription := make([]clobtypes.StreamUpdate, 0)
Expand Down Expand Up @@ -215,9 +221,6 @@ func (sm *GrpcStreamingManagerImpl) sendStreamUpdate(
1,
)

sm.Lock()
defer sm.Unlock()

// Send updates to subscribers.
idsToRemove := make([]uint32, 0)
for id, subscription := range sm.orderbookSubscriptions {
Expand Down

0 comments on commit a8619a7

Please sign in to comment.