Skip to content

Commit

Permalink
Merge pull request #49 from ddosify/request_clients_prevent_race
Browse files Browse the repository at this point in the history
prevent race condition on request clients map
  • Loading branch information
fatihbaltaci authored Feb 15, 2022
2 parents b3929eb + 5a60cfc commit 867beef
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions core/scenario/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"net/url"
"strconv"
"strings"
"sync"
"time"

"go.ddosify.com/ddosify/core/scenario/requester"
Expand All @@ -41,6 +42,8 @@ type ScenarioService struct {

scenario types.Scenario
ctx context.Context

clientMutex sync.Mutex
}

// NewScenarioService is the constructor of the ScenarioService.
Expand Down Expand Up @@ -96,6 +99,9 @@ func (s *ScenarioService) Do(proxy *url.URL, startTime time.Time) (response *typ
}

func (s *ScenarioService) getOrCreateRequesters(proxy *url.URL) (requesters []scenarioItemRequester, err error) {
s.clientMutex.Lock()
defer s.clientMutex.Unlock()

requesters, ok := s.clients[proxy]
if !ok {
err = s.createRequesters(proxy)
Expand Down

0 comments on commit 867beef

Please sign in to comment.