mirror of
https://github.com/nxtrace/NTrace-core.git
synced 2025-08-12 06:26:39 +00:00
try fix: #67 fatal error: concurrent map read and map write
This commit is contained in:
@@ -52,7 +52,9 @@ func (t *ICMPTracer) PrintFunc() {
|
||||
}
|
||||
|
||||
func (t *ICMPTracer) Execute() (*Result, error) {
|
||||
t.inflightRequestLock.Lock()
|
||||
t.inflightRequest = make(map[int]chan Hop)
|
||||
t.inflightRequestLock.Unlock()
|
||||
|
||||
if len(t.res.Hops) > 0 {
|
||||
return &t.res, ErrTracerouteExecuted
|
||||
|
||||
@@ -53,7 +53,9 @@ func (t *ICMPTracerv6) PrintFunc() {
|
||||
}
|
||||
|
||||
func (t *ICMPTracerv6) Execute() (*Result, error) {
|
||||
t.inflightRequestLock.Lock()
|
||||
t.inflightRequest = make(map[int]chan Hop)
|
||||
t.inflightRequestLock.Unlock()
|
||||
|
||||
if len(t.res.Hops) > 0 {
|
||||
return &t.res, ErrTracerouteExecuted
|
||||
|
||||
@@ -60,7 +60,10 @@ func (t *TCPTracer) Execute() (*Result, error) {
|
||||
var cancel context.CancelFunc
|
||||
t.ctx, cancel = context.WithCancel(context.Background())
|
||||
defer cancel()
|
||||
t.inflightRequestLock.Lock()
|
||||
t.inflightRequest = make(map[int]chan Hop)
|
||||
t.inflightRequestLock.Unlock()
|
||||
|
||||
t.final = -1
|
||||
|
||||
go t.listenICMP()
|
||||
@@ -161,7 +164,7 @@ func (t *TCPTracer) listenTCP() {
|
||||
if tcpLayer := packet.Layer(layers.LayerTypeTCP); tcpLayer != nil {
|
||||
tcp, _ := tcpLayer.(*layers.TCP)
|
||||
// 取得目标主机的Sequence Number
|
||||
|
||||
t.inflightRequestLock.Lock()
|
||||
if ch, ok := t.inflightRequest[int(tcp.Ack-1)]; ok {
|
||||
// 最后一跳
|
||||
ch <- Hop{
|
||||
@@ -169,6 +172,7 @@ func (t *TCPTracer) listenTCP() {
|
||||
Address: msg.Peer,
|
||||
}
|
||||
}
|
||||
t.inflightRequestLock.Unlock()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -121,8 +121,8 @@ func (t *UDPTracer) handleICMPMessage(msg ReceivedMessage, data []byte) {
|
||||
return
|
||||
}
|
||||
srcPort := util.GetUDPSrcPort(header)
|
||||
//t.inflightRequestLock.Lock()
|
||||
//defer t.inflightRequestLock.Unlock()
|
||||
t.inflightRequestLock.Lock()
|
||||
defer t.inflightRequestLock.Unlock()
|
||||
ch, ok := t.inflightRequest[int(srcPort)]
|
||||
if !ok {
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user