Skip to content
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

[dbnode] Fix integration code under race with TChannel channel options mutation issue #2958

Merged
merged 2 commits into from
Nov 30, 2020
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
11 changes: 9 additions & 2 deletions src/dbnode/client/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -318,9 +318,16 @@ func NewOptionsForAsyncClusters(opts Options, topoInits []topology.Initializer,
}

func defaultNewConnectionFn(
channelName string, address string, opts Options,
channelName string, address string, clientOpts Options,
) (xresource.SimpleCloser, rpc.TChanNode, error) {
channel, err := tchannel.NewChannel(channelName, opts.ChannelOptions())
// NB(r): Keep ref to a local channel options since it's actually modified
// by TChannel itself to set defaults.
var opts *tchannel.ChannelOptions
if chanOpts := clientOpts.ChannelOptions(); chanOpts != nil {
immutableOpts := *chanOpts
opts = &immutableOpts
}
channel, err := tchannel.NewChannel(channelName, opts)
if err != nil {
return nil, nil, err
}
Expand Down
14 changes: 8 additions & 6 deletions src/dbnode/network/server/tchannelthrift/cluster/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,6 @@ func NewServer(
contextPool context.Pool,
opts *tchannel.ChannelOptions,
) ns.NetworkService {
// Make the opts immutable on the way in
if opts != nil {
immutableOpts := *opts
opts = &immutableOpts
}
return &server{
address: address,
client: client,
Expand All @@ -64,7 +59,14 @@ func NewServer(
}

func (s *server) ListenAndServe() (ns.Close, error) {
channel, err := tchannel.NewChannel(ChannelName, s.opts)
// NB(r): Keep ref to a local channel options since it's actually modified
// by TChannel itself to set defaults.
var opts *tchannel.ChannelOptions
if s.opts != nil {
immutableOpts := *s.opts
opts = &immutableOpts
}
channel, err := tchannel.NewChannel(ChannelName, opts)
if err != nil {
return nil, err
}
Expand Down
10 changes: 8 additions & 2 deletions src/dbnode/network/server/tchannelthrift/node/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,14 @@ func NewServer(
}

func (s *server) ListenAndServe() (ns.Close, error) {
chanOpts := s.opts.ChannelOptions()
channel, err := tchannel.NewChannel(channel.ChannelName, chanOpts)
// NB(r): Keep ref to a local channel options since it's actually modified
// by TChannel itself to set defaults.
var opts *tchannel.ChannelOptions
if chanOpts := s.opts.ChannelOptions(); chanOpts != nil {
immutableOpts := *chanOpts
opts = &immutableOpts
}
channel, err := tchannel.NewChannel(channel.ChannelName, opts)
if err != nil {
return nil, err
}
Expand Down