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
net: each Read, ReadFrom variants doesn't take care of a shared buffer which is used by multiple goroutines #8858
Labels
Comments
Here is a sample Google Go Code Plus Python Code to generate the test. You must set up a linux server with 5 IP addresses on the ethernet port. I am sure you could probably just change the ports around and use a single IP address, but that is not the test that I ran to produce the bugs. You will observe the "Mangled Bytes" error message and that will indicate that the UDP payload does not match the IP Address. ##############GO CODE################## // testudp project main.go package main import ( "fmt" "net" "os" "os/signal" "strings" "syscall" "time" ) var gmax int = 0 var gstop bool = false func main() { fmt.Println("TestUdp Starting up:", time.Now().UTC().String()) gsigchan := make(chan os.Signal, 3) signal.Notify(gsigchan, os.Interrupt, syscall.SIGTERM) signal.Notify(gsigchan, os.Interrupt, syscall.SIGUSR1) go func() { <-gsigchan fmt.Println("TestUDP SIGTERM:", time.Now().UTC().String()) gstop = true }() go udplisten("192.168.7.20", 8500, &gstop) for { time.Sleep(1000 * time.Millisecond) if gstop == true { break } //fmt.Println("TestUdp Running:", time.Now().UTC().String()) } fmt.Println("TestUdp Exiting:", time.Now().UTC().String()) time.Sleep(100 * time.Millisecond) } func udplisten(gip string, gport int, gstop *bool) bool { //Parameters //gip - IP Address will listen to //gport - Port we will listen on //gstop - pointer to control variable to terminate thread var gbuf [1024]byte if gip == "" { fmt.Println("Invalid IP Address") return false } if gport < 3000 { fmt.Println("Invalid Port") return false } if gstop == nil { fmt.Println("Invalid Stop variable") return false } gsrvaddr := net.UDPAddr{ Port: gport, IP: net.ParseIP(gip), } fmt.Println("UDP Listen ENTER:", gsrvaddr) for *gstop == false { gconn, gerr := net.ListenUDP("udp4", &gsrvaddr) if gerr != nil { fmt.Println("Cluster UDP Listen Error:", gerr) time.Sleep(1000 * time.Millisecond) continue } for *gstop == false { //#give us 1 second to read the bytes gconn.SetReadDeadline(time.Now().Add(time.Second)) glen, grxadd, gerr := gconn.ReadFromUDP(gbuf[0:]) if gerr != nil { //Remove timeout from this loop if strings.Contains(gerr.Error(), "i/o timeout") == true { continue } fmt.Println("UDP Read Error:", gerr) gconn.Close() break } if grxadd == nil { time.Sleep(200 * time.Millisecond) fmt.Println("UDP No Address returned on RX") continue } go udpcallbackfunc(gconn, grxadd, glen, gbuf[0:glen]) } } return true } func udpcallbackfunc(grxconn *net.UDPConn, grxadd *net.UDPAddr, grxlen int, grx []byte) { gstr := string(grx) if gstr == grxadd.IP.String() { //Our grx payload is good return } fmt.Println("Bytes Mangled:", gstr, grxadd.IP.String()) gmax++ if gmax > 200 { gstop = true } return } ##############PYTHON CODE################## import time from socket import * from threading import Thread gstop = 0 def udpcli(srvaddr,cliaddr,payload): sock = socket(AF_INET,SOCK_DGRAM) sock.bind(cliaddr) print "UDP Thread going..." print cliaddr print srvaddr print payload while True: #Just send it a lot sock.sendto(payload,srvaddr) if gstop == 1: break print "UDP Thread stopping" print payload saddr = ("192.168.7.20",8500) caddr = ("192.168.7.21",8500) ta = Thread(target=udpcli,args=(saddr,caddr,"192.168.7.21")) ta.start() caddr = ("192.168.7.22",8500) tb = Thread(target=udpcli,args=(saddr,caddr,"192.168.7.22")) tb.start() caddr = ("192.168.7.23",8500) tc = Thread(target=udpcli,args=(saddr,caddr,"192.168.7.23")) tc.start() caddr = ("192.168.7.24",8500) td = Thread(target=udpcli,args=(saddr,caddr,"192.168.7.24")) td.start() print "Started UDP client" while 1: if gstop == 1: break try: time.sleep(1) print "Running UDP client" except KeyboardInterrupt: print "Keyboard Break" gstop = 1 break print "Broken Out Break" time.sleep(1) print "Stopped..." |
Status changed to Duplicate. Merged into issue #8881. |
This issue was closed.
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
by rpzrpzrpz:
The text was updated successfully, but these errors were encountered: