Skip to content

Commit 7969412

Browse files
author
Divjot Arora
committed
GODRIVER-1719 Resolve data race between mongotest and proxy dialer (#488)
1 parent 8b57925 commit 7969412

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

mongo/integration/mtest/mongotest.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,7 @@ func (t *T) GetProxiedMessages() []*ProxyMessage {
354354
if t.proxyDialer == nil {
355355
return nil
356356
}
357-
return t.proxyDialer.messages
357+
return t.proxyDialer.Messages()
358358
}
359359

360360
// ClearEvents clears the existing command monitoring events.

mongo/integration/mtest/proxy_dialer.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,19 @@ func (p *proxyDialer) storeReceivedMessage(wm []byte, addr string) error {
129129
return nil
130130
}
131131

132+
// Messages returns a slice of proxied messages. This slice is a copy of the messages proxied so far and will not be
133+
// updated for messages proxied after this call.
134+
func (p *proxyDialer) Messages() []*ProxyMessage {
135+
p.Lock()
136+
defer p.Unlock()
137+
138+
copiedMessages := make([]*ProxyMessage, 0, len(p.messages))
139+
for _, msg := range p.messages {
140+
copiedMessages = append(copiedMessages, msg)
141+
}
142+
return copiedMessages
143+
}
144+
132145
// proxyConn is a net.Conn that wraps a network connection. All messages sent/received through a proxyConn are stored
133146
// in the associated proxyDialer and are forwarded over the wrapped connection. Errors encountered when parsing and
134147
// storing wire messages are wrapped to add context, while errors returned from the underlying network connection are

0 commit comments

Comments
 (0)