-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
swarm: log unexpected listener errors #2277
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -127,6 +127,9 @@ func (s *Swarm) AddListenAddr(a ma.Multiaddr) error { | |||||
for { | ||||||
c, err := list.Accept() | ||||||
if err != nil { | ||||||
if err != transport.ErrListenerClosed { | ||||||
log.Error("swarm listener accept error: ", err) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should this include which listener this is? For example:
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What do you think about using "%T" to print the type? I think it'll be more useful than trying to print the fields on some unknown struct. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What fields of an unknown struct? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You're right. I misread this as |
||||||
} | ||||||
return | ||||||
} | ||||||
canonicallog.LogPeerStatus(100, c.RemotePeer(), c.RemoteMultiaddr(), "connection_status", "established", "dir", "inbound") | ||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,7 @@ import ( | |
|
||
"github.com/libp2p/go-libp2p/core/crypto" | ||
"github.com/libp2p/go-libp2p/core/peer" | ||
"github.com/libp2p/go-libp2p/core/transport" | ||
libp2ptls "github.com/libp2p/go-libp2p/p2p/security/tls" | ||
|
||
ma "github.com/multiformats/go-multiaddr" | ||
|
@@ -152,8 +153,7 @@ func TestAcceptErrorGetCleanedUp(t *testing.T) { | |
require.NoError(t, err) | ||
defer l.Close() | ||
_, err = l.Accept(context.Background()) | ||
require.EqualError(t, err, "accept goroutine finished") | ||
|
||
require.Equal(t, err, transport.ErrListenerClosed) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
} | ||
|
||
// The connection passed to quic-go needs to be type-assertable to a net.UDPConn, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,8 +7,10 @@ import ( | |
"fmt" | ||
"io" | ||
"net" | ||
"strings" | ||
"sync" | ||
|
||
"github.com/libp2p/go-libp2p/core/transport" | ||
ma "github.com/multiformats/go-multiaddr" | ||
"github.com/quic-go/quic-go" | ||
) | ||
|
@@ -134,6 +136,9 @@ func (l *connListener) Run() error { | |
for { | ||
conn, err := l.l.Accept(context.Background()) | ||
if err != nil { | ||
if err == quic.ErrServerClosed || strings.Contains(err.Error(), "use of closed network connection") { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
return transport.ErrListenerClosed | ||
} | ||
return err | ||
} | ||
proto := conn.ConnectionState().TLS.NegotiatedProtocol | ||
|
@@ -192,10 +197,10 @@ func (l *listener) Accept(ctx context.Context) (quic.Connection, error) { | |
case <-ctx.Done(): | ||
return nil, ctx.Err() | ||
case <-l.acceptLoopRunning: | ||
return nil, errors.New("accept goroutine finished") | ||
return nil, transport.ErrListenerClosed | ||
case c, ok := <-l.queue: | ||
if !ok { | ||
return nil, errors.New("listener closed") | ||
return nil, transport.ErrListenerClosed | ||
} | ||
return c, nil | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
errors.Is
?