mirror of
https://github.com/cwinfo/yggdrasil-go.git
synced 2024-12-23 07:35:39 +00:00
Fix race condition between incoming and outgoing connection setup
This commit is contained in:
parent
8562b6b86e
commit
06ca8941c7
@ -268,8 +268,6 @@ func (l *links) add(u *url.URL, sintf string, linkType linkType) error {
|
|||||||
// Clear the error state.
|
// Clear the error state.
|
||||||
state.Lock()
|
state.Lock()
|
||||||
state._conn = lc
|
state._conn = lc
|
||||||
state._err = nil
|
|
||||||
state._errtime = time.Time{}
|
|
||||||
state.Unlock()
|
state.Unlock()
|
||||||
|
|
||||||
// Give the connection to the handler. The handler will block
|
// Give the connection to the handler. The handler will block
|
||||||
@ -368,10 +366,18 @@ func (l *links) listen(u *url.URL, sintf string) (*Listener, error) {
|
|||||||
// connection. This prevents duplicate peerings.
|
// connection. This prevents duplicate peerings.
|
||||||
l.Lock()
|
l.Lock()
|
||||||
state, ok := l._links[info]
|
state, ok := l._links[info]
|
||||||
if ok && state != nil && state._conn != nil {
|
if ok && state != nil {
|
||||||
|
switch {
|
||||||
|
case state._conn != nil:
|
||||||
|
// We are already connected to something.
|
||||||
|
case state._conn == nil && state._errtime == time.Time{}:
|
||||||
|
// We aren't connected yet, but the fact that there
|
||||||
|
// is no last error suggests we haven't yet attempted
|
||||||
|
// an outbound connection at all.
|
||||||
l.Unlock()
|
l.Unlock()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if !ok || state == nil {
|
if !ok || state == nil {
|
||||||
state = &link{
|
state = &link{
|
||||||
linkType: linkTypeIncoming,
|
linkType: linkTypeIncoming,
|
||||||
|
Loading…
Reference in New Issue
Block a user