Skip to content

Commit

Permalink
Merge pull request #85 from renproject/fix/memory-leak
Browse files Browse the repository at this point in the history
Fix potential memory leak in Channel
  • Loading branch information
tok-kkk committed Jul 14, 2021
2 parents 50d6a64 + 2e6270d commit ebabd86
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
1 change: 1 addition & 0 deletions channel/channel.go
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,7 @@ func (ch *Channel) readLoop(ctx context.Context) error {
for {
select {
case <-ctx.Done():
close(drain)
return ctx.Err()
case r := <-ch.readers:
ch.opts.Logger.Debug("replaced reader", zap.String("remote", ch.remote.String()), zap.String("addr", r.Conn.RemoteAddr().String()))
Expand Down
25 changes: 25 additions & 0 deletions peer/opt.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,26 @@ func DefaultDiscoveryOptions() DiscoveryOptions {
}
}

func (opts DiscoveryOptions) WithLogger(logger *zap.Logger) DiscoveryOptions {
opts.Logger = logger
return opts
}

func (opts DiscoveryOptions) WithAlpha(alpha int) DiscoveryOptions {
opts.Alpha = alpha
return opts
}

func (opts DiscoveryOptions) WithMaxExpectedPeers(max int) DiscoveryOptions {
opts.MaxExpectedPeers = max
return opts
}

func (opts DiscoveryOptions) WithPingTimePeriod(period time.Duration) DiscoveryOptions {
opts.PingTimePeriod = period
return opts
}

type Options struct {
SyncerOptions
GossiperOptions
Expand Down Expand Up @@ -128,6 +148,11 @@ func (opts Options) WithGossiperOptions(gossiperOptions GossiperOptions) Options
return opts
}

func (opts Options) WithDiscoveryOptions(discoveryOptions DiscoveryOptions) Options {
opts.DiscoveryOptions = discoveryOptions
return opts
}

func (opts Options) WithLogger(logger *zap.Logger) Options {
opts.Logger = logger
return opts
Expand Down

0 comments on commit ebabd86

Please sign in to comment.