mirror of
https://github.com/yggdrasil-network/yggdrasil-go.git
synced 2024-11-23 18:15:24 +00:00
Fix con urrent map accesses
This commit is contained in:
parent
e290e744f4
commit
6e338b6f89
@ -152,7 +152,12 @@ func (l *links) add(u *url.URL, sintf string, linkType linkType) error {
|
|||||||
sintf: sintf,
|
sintf: sintf,
|
||||||
linkType: linkType,
|
linkType: linkType,
|
||||||
}
|
}
|
||||||
if state, ok := l._links[info]; ok {
|
var state *link
|
||||||
|
var ok bool
|
||||||
|
phony.Block(l, func() {
|
||||||
|
state, ok = l._links[info]
|
||||||
|
})
|
||||||
|
if ok && state != nil {
|
||||||
select {
|
select {
|
||||||
case state.kick <- struct{}{}:
|
case state.kick <- struct{}{}:
|
||||||
default:
|
default:
|
||||||
@ -164,7 +169,7 @@ func (l *links) add(u *url.URL, sintf string, linkType linkType) error {
|
|||||||
// in progress (if any), any error details and a context that
|
// in progress (if any), any error details and a context that
|
||||||
// lets the link be cancelled later.
|
// lets the link be cancelled later.
|
||||||
ctx, cancel := context.WithCancel(l.core.ctx)
|
ctx, cancel := context.WithCancel(l.core.ctx)
|
||||||
state := &link{
|
state = &link{
|
||||||
info: info,
|
info: info,
|
||||||
linkProto: strings.ToUpper(u.Scheme),
|
linkProto: strings.ToUpper(u.Scheme),
|
||||||
ctx: ctx,
|
ctx: ctx,
|
||||||
@ -327,8 +332,12 @@ func (l *links) listen(u *url.URL, sintf string) (*Listener, error) {
|
|||||||
_ = conn.Close()
|
_ = conn.Close()
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
state := l._links[info]
|
var state *link
|
||||||
if state == nil {
|
var ok bool
|
||||||
|
phony.Block(l, func() {
|
||||||
|
state = l._links[info]
|
||||||
|
})
|
||||||
|
if !ok || state == nil {
|
||||||
state = &link{
|
state = &link{
|
||||||
info: info,
|
info: info,
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user