Skip to content

Commit f9c256e

Browse files
authored
Merge pull request #289 from Thiht/fix/deadlock
fix: deadlock
2 parents 583e7d3 + 2102d9b commit f9c256e

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

server/handlers/mocks.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,6 @@ func NewMocks(ms services.Mocks) *Mocks {
2828
}
2929

3030
func (m *Mocks) GenericHandler(c echo.Context) error {
31-
m.mu.Lock()
32-
defer m.mu.Unlock()
33-
3431
actualRequest := types.HTTPRequestToRequest(c.Request())
3532
b, _ := yaml.Marshal(actualRequest)
3633
log.Debugf("Received request:\n---\n%s\n", string(b))
@@ -91,7 +88,9 @@ func (m *Mocks) GenericHandler(c echo.Context) error {
9188
response = mock.Response
9289
}
9390

91+
m.mu.Lock()
9492
matchingMock.State.TimesCount++
93+
m.mu.Unlock()
9594
break
9695
} else {
9796
b, _ = yaml.Marshal(mock)
@@ -107,7 +106,9 @@ func (m *Mocks) GenericHandler(c echo.Context) error {
107106

108107
if len(exceededMocks) > 0 {
109108
for _, mock := range exceededMocks {
109+
m.mu.Lock()
110110
mock.State.TimesCount++
111+
m.mu.Unlock()
111112
}
112113
resp["message"] = types.SmockerMockExceeded
113114
resp["nearest"] = exceededMocks

0 commit comments

Comments
 (0)