Skip to content

Commit

Permalink
fix race condition
Browse files Browse the repository at this point in the history
  • Loading branch information
ross-pure committed Apr 1, 2021
1 parent 1a5f822 commit ecacf31
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions transport/transport.go
Original file line number Diff line number Diff line change
Expand Up @@ -243,8 +243,6 @@ func (t *Transport) run(ctx context.Context) {
enc = codec.LengthPrefixEncoder(codec.PlainEncoder, enc)
dec = codec.LengthPrefixDecoder(codec.PlainDecoder, dec)

t.connect(remote)
defer t.disconnect(remote)

// If the Transport is linked to the remote peer, then the
// network connection should be kept alive until the remote peer
Expand All @@ -256,6 +254,8 @@ func (t *Transport) run(ctx context.Context) {
// Attaching a connection will block until the Channel is
// unbound (which happens when the Transport is unlinked), the
// connection is replaced, or the connection faults.
t.connect(remote)
defer t.disconnect(remote)
if err := t.client.Attach(ctx, remote, conn, enc, dec); err != nil {
t.opts.Logger.Error("incoming attachment", zap.String("remote", remote.String()), zap.String("addr", addr), zap.Error(err))
}
Expand All @@ -274,6 +274,8 @@ func (t *Transport) run(ctx context.Context) {
t.client.Bind(remote)
defer t.client.Unbind(remote)

t.connect(remote)
defer t.disconnect(remote)
if err := t.client.Attach(ctx, remote, conn, enc, dec); err != nil {
t.opts.Logger.Error("incoming attachment", zap.String("remote", remote.String()), zap.String("addr", addr), zap.Error(err))
}
Expand Down

0 comments on commit ecacf31

Please sign in to comment.