Skip to content

Commit

Permalink
fix: remove unnecessary block from websocket subtask creator (#809)
Browse files Browse the repository at this point in the history
  • Loading branch information
technicallyty authored Oct 31, 2024
1 parent 7355199 commit c5b2cfc
Showing 1 changed file with 2 additions and 24 deletions.
26 changes: 2 additions & 24 deletions providers/base/fetch.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (

"go.uber.org/zap"

"github.com/skip-mev/connect/v2/pkg/slices"
providermetrics "github.com/skip-mev/connect/v2/providers/base/metrics"
providertypes "github.com/skip-mev/connect/v2/providers/types"
)
Expand Down Expand Up @@ -85,23 +86,8 @@ func (p *Provider[K, V]) startMultiplexWebsocket(ctx context.Context) error {
if maxSubsPerConn > 0 {
// case where we will split ID's across sub handlers
numSubHandlers := int(math.Ceil(float64(len(ids)) / float64(maxSubsPerConn)))
p.logger.Debug("setting number of web socket handlers for provider", zap.Int("sub_handlers", numSubHandlers))
wg.SetLimit(numSubHandlers)

// split ids
for i := 0; i < numSubHandlers; i++ {
start := i * maxSubsPerConn

// Copy the IDs over.
subIDs := make([]K, 0)
if end := start + maxSubsPerConn; end >= len(ids) {
subIDs = append(subIDs, ids[start:]...)
} else {
subIDs = append(subIDs, ids[start:end]...)
}

subTasks = append(subTasks, subIDs)
}
subTasks = slices.Chunk(ids, maxSubsPerConn)
} else {
// case where there is 1 sub handler
subTasks = append(subTasks, ids)
Expand All @@ -110,14 +96,6 @@ func (p *Provider[K, V]) startMultiplexWebsocket(ctx context.Context) error {

for _, subIDs := range subTasks {
wg.Go(p.startWebSocket(ctx, subIDs))

select {
case <-time.After(p.wsCfg.HandshakeTimeout):
p.logger.Debug("handshake timeout reached")
case <-ctx.Done():
p.logger.Debug("context done")
return wg.Wait()
}
}

// Wait for all the sub handlers to finish.
Expand Down

0 comments on commit c5b2cfc

Please sign in to comment.