Skip to content

Commit 867beef

Browse files
authored
Merge pull request #49 from ddosify/request_clients_prevent_race
prevent race condition on request clients map
2 parents b3929eb + 5a60cfc commit 867beef

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

core/scenario/service.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import (
2626
"net/url"
2727
"strconv"
2828
"strings"
29+
"sync"
2930
"time"
3031

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

4243
scenario types.Scenario
4344
ctx context.Context
45+
46+
clientMutex sync.Mutex
4447
}
4548

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

98101
func (s *ScenarioService) getOrCreateRequesters(proxy *url.URL) (requesters []scenarioItemRequester, err error) {
102+
s.clientMutex.Lock()
103+
defer s.clientMutex.Unlock()
104+
99105
requesters, ok := s.clients[proxy]
100106
if !ok {
101107
err = s.createRequesters(proxy)

0 commit comments

Comments
 (0)