Skip to content

GODRIVER-1719 Resolve data race between mongotest and proxy dialer #488

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
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 mongo/integration/mtest/mongotest.go
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ func (t *T) GetProxiedMessages() []*ProxyMessage {
if t.proxyDialer == nil {
return nil
}
return t.proxyDialer.messages
return t.proxyDialer.Messages()
}

// ClearEvents clears the existing command monitoring events.
Expand Down
13 changes: 13 additions & 0 deletions mongo/integration/mtest/proxy_dialer.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,19 @@ func (p *proxyDialer) storeReceivedMessage(wm []byte, addr string) error {
return nil
}

// Messages returns a slice of proxied messages. This slice is a copy of the messages proxied so far and will not be
// updated for messages proxied after this call.
func (p *proxyDialer) Messages() []*ProxyMessage {
p.Lock()
defer p.Unlock()

copiedMessages := make([]*ProxyMessage, 0, len(p.messages))
for _, msg := range p.messages {
copiedMessages = append(copiedMessages, msg)
}
return copiedMessages
}

// proxyConn is a net.Conn that wraps a network connection. All messages sent/received through a proxyConn are stored
// in the associated proxyDialer and are forwarded over the wrapped connection. Errors encountered when parsing and
// storing wire messages are wrapped to add context, while errors returned from the underlying network connection are
Expand Down