Skip to content

Commit

Permalink
Don't run concurrent purple pages requests (#55)
Browse files Browse the repository at this point in the history
This is very silly and error prone as we ignore context timeouts in
favour of waitinf for the mutex but it is what it is.
  • Loading branch information
boreq authored Nov 14, 2023
1 parent b78cf27 commit b2aeb26
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions service/adapters/purple_pages.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package adapters

import (
"context"
"sync"
"time"

"github.com/boreq/errors"
Expand All @@ -25,6 +26,7 @@ type PurplePages struct {
logger logging.Logger
metrics app.Metrics
connection *RelayConnection
mutex sync.Mutex // purple pages isn't happy when we open too many concurrent requests
}

func NewPurplePages(
Expand All @@ -45,6 +47,9 @@ func NewPurplePages(
func (p *PurplePages) GetRelays(ctx context.Context, publicKey domain.PublicKey) (result []domain.RelayAddress, err error) {
defer p.metrics.ReportPurplePagesLookupResult(&err)

p.mutex.Lock()
defer p.mutex.Unlock()

ctx, cancel := context.WithCancel(ctx)
defer cancel()

Expand Down

0 comments on commit b2aeb26

Please sign in to comment.