Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion field_map.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ func (m FieldMap) GetTime(tag Tag) (t time.Time, err MessageRejectError) {
m.rwLock.RLock()
defer m.rwLock.RUnlock()

bytes, err := m.GetBytes(tag)
bytes, err := m.getBytesNoLock(tag)
if err != nil {
return
}
Expand Down
45 changes: 45 additions & 0 deletions field_map_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ package quickfix

import (
"bytes"
"sync"
"testing"
"time"

"github.com/stretchr/testify/assert"
)
Expand Down Expand Up @@ -202,3 +204,46 @@ func TestFieldMap_Remove(t *testing.T) {
assert.False(t, fMap.Has(1))
assert.True(t, fMap.Has(2))
}

// TestFieldMap_GetTimeConcurrentWithSet verifies the fix guarding against
// recursive read-locking in GetTime.
func TestFieldMap_GetTimeConcurrentWithSet(t *testing.T) {
var fMap FieldMap
fMap.init()
fMap.SetField(Tag(1), FIXUTCTimestamp{Time: time.Now()})
fMap.SetField(Tag(2), FIXString("blah"))

var wg sync.WaitGroup
wg.Add(1)
go func() {
defer wg.Done()
for i := 0; i < 50000; i++ {
fMap.SetField(Tag(2), FIXString("blah"))
}
}()

for r := 0; r < 8; r++ {
wg.Add(1)
go func() {
defer wg.Done()
for i := 0; i < 50000; i++ {
if _, err := fMap.GetTime(Tag(1)); err != nil {
t.Error(err)
return
}
}
}()
}

done := make(chan struct{})
go func() {
wg.Wait()
close(done)
}()

select {
case <-done:
case <-time.After(60 * time.Second):
t.Fatal("deadlock: GetTime did not complete concurrently with writers")
}
}
Loading