Skip to content

Commit

Permalink
BAARC-148: Feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
boecklim committed May 15, 2024
1 parent e168693 commit 4afd278
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions peer.go
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ func (p *Peer) readRetry(ctx context.Context, r io.Reader, pver uint32, bsvnet w
return nil, readMessageErr
}

func (p *Peer) startReadHandler(cancelCtx context.Context) {
func (p *Peer) startReadHandler(ctx context.Context) {
p.logger.Debug("Starting read handler")

defer func() {
Expand All @@ -392,11 +392,11 @@ func (p *Peer) startReadHandler(cancelCtx context.Context) {
reader := bufio.NewReader(&io.LimitedReader{R: readConn, N: p.maximumMessageSize})
for {
select {
case <-cancelCtx.Done():
case <-ctx.Done():
p.logger.Debug("Read handler canceled")
return
default:
msg, err = p.readRetry(cancelCtx, reader, wire.ProtocolVersion, p.network)
msg, err = p.readRetry(ctx, reader, wire.ProtocolVersion, p.network)
if err != nil {
if errors.Is(err, context.Canceled) {
p.logger.Debug("Retrying to read canceled")
Expand Down Expand Up @@ -659,7 +659,7 @@ func (p *Peer) writeRetry(ctx context.Context, msg wire.Message) error {
return backoff.RetryNotify(operation, policyContext, notify)
}

func (p *Peer) startWriteChannelHandler(cancelCtx context.Context, instance int) {
func (p *Peer) startWriteChannelHandler(ctx context.Context, instance int) {
p.logger.Debug("Starting write handler", slog.Int("instance", instance))

defer func() {
Expand All @@ -669,7 +669,7 @@ func (p *Peer) startWriteChannelHandler(cancelCtx context.Context, instance int)

for {
select {
case <-cancelCtx.Done():
case <-ctx.Done():
p.logger.Debug("Write handler canceled", slog.Int("instance", instance))
return
case msg := <-p.writeChan:
Expand All @@ -684,7 +684,7 @@ func (p *Peer) startWriteChannelHandler(cancelCtx context.Context, instance int)
}
time.Sleep(100 * time.Millisecond)
}
err := p.writeRetry(cancelCtx, msg)
err := p.writeRetry(ctx, msg)
if err != nil {
if errors.Is(err, context.Canceled) {
p.logger.Debug("Retrying to write canceled", slog.Int("instance", instance))
Expand Down

0 comments on commit 4afd278

Please sign in to comment.