Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
adam.huang
go-libp2p
Commits
0d2ae7b7
Commit
0d2ae7b7
authored
Apr 06, 2016
by
Jeromy
Browse files
don't break listener on failed msmux negotiation
parent
fe95f0a0
Changes
2
Hide whitespace changes
Inline
Side-by-side
p2p/net/conn/dial_test.go
View file @
0d2ae7b7
package
conn
package
conn
import
(
import
(
"bytes"
"fmt"
"fmt"
"io"
"io"
"net"
"net"
...
@@ -349,3 +350,50 @@ func TestMultistreamHeader(t *testing.T) {
...
@@ -349,3 +350,50 @@ func TestMultistreamHeader(t *testing.T) {
t
.
Fatal
(
err
)
t
.
Fatal
(
err
)
}
}
}
}
func
TestFailedAccept
(
t
*
testing
.
T
)
{
ctx
,
cancel
:=
context
.
WithCancel
(
context
.
Background
())
defer
cancel
()
p1
:=
tu
.
RandPeerNetParamsOrFatal
(
t
)
l1
,
err
:=
Listen
(
ctx
,
p1
.
Addr
,
p1
.
ID
,
p1
.
PrivKey
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
p1
.
Addr
=
l1
.
Multiaddr
()
// Addr has been determined by kernel.
done
:=
make
(
chan
struct
{})
go
func
()
{
defer
close
(
done
)
con
,
err
:=
net
.
Dial
(
"tcp"
,
l1
.
Addr
()
.
String
())
if
err
!=
nil
{
t
.
Error
(
"first dial failed: "
,
err
)
}
// write some garbage
con
.
Write
(
bytes
.
Repeat
([]
byte
{
255
},
1000
))
con
.
Close
()
con
,
err
=
net
.
Dial
(
"tcp"
,
l1
.
Addr
()
.
String
())
if
err
!=
nil
{
t
.
Error
(
"second dial failed: "
,
err
)
}
defer
con
.
Close
()
err
=
msmux
.
SelectProtoOrFail
(
SecioTag
,
con
)
if
err
!=
nil
{
t
.
Error
(
"msmux select failed: "
,
err
)
}
}()
c
,
err
:=
l1
.
Accept
()
if
err
!=
nil
{
t
.
Fatal
(
"connections after a failed accept should still work: "
,
err
)
}
c
.
Close
()
<-
done
}
p2p/net/conn/listen.go
View file @
0d2ae7b7
...
@@ -106,7 +106,8 @@ func (l *listener) Accept() (net.Conn, error) {
...
@@ -106,7 +106,8 @@ func (l *listener) Accept() (net.Conn, error) {
_
,
_
,
err
=
l
.
mux
.
Negotiate
(
maconn
)
_
,
_
,
err
=
l
.
mux
.
Negotiate
(
maconn
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
log
.
Info
(
"negotiation of crypto protocol failed: "
,
err
)
continue
}
}
c
,
err
:=
newSingleConn
(
ctx
,
l
.
local
,
""
,
maconn
)
c
,
err
:=
newSingleConn
(
ctx
,
l
.
local
,
""
,
maconn
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment