-
-
Save arnaud-lb/3af01cdfb6b1ee38c122 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"log" | |
"math/rand" | |
"net" | |
"runtime" | |
"strconv" | |
"syscall" | |
) | |
var dns = make(chan interface{}, 10000) | |
var unix = make(chan interface{}, 20000) | |
func test() { | |
for { | |
dns <- nil | |
go func() { | |
for { | |
hn := strconv.FormatInt(int64(rand.Int31()), 10) + ".com" | |
net.ResolveIPAddr("ip", hn) | |
log.Print(hn) | |
} | |
<-dns | |
}() | |
} | |
} | |
func main() { | |
runtime.GOMAXPROCS(8) | |
if err := syscall.Setrlimit(syscall.RLIMIT_NOFILE, &syscall.Rlimit{Max: 50000, Cur: 50000}); err != nil { | |
log.Printf("failed setting syscall.RLIMIT_NOFILE to 50K, the bug will not be reproducible") | |
return | |
} | |
go test() | |
for { | |
unix <- nil | |
go func() { | |
var err error | |
var conn net.Conn | |
for { | |
conn, err = net.Dial("unix", "/tmp/test.sock") | |
if err != nil { | |
log.Print(err) | |
} else { | |
break | |
} | |
} | |
if err != nil { | |
return | |
} | |
conn.Write([]byte("foo\n")) | |
conn.Write([]byte("bar\n")) | |
conn.Write([]byte("baz\n")) | |
conn.Close() | |
<-unix | |
}() | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"io" | |
"log" | |
"net" | |
"os" | |
) | |
const sockpath = "/tmp/test.sock" | |
func main() { | |
os.Remove(sockpath) | |
ln, err := net.Listen("unix", sockpath) | |
if err != nil { | |
panic(err) | |
} | |
for { | |
conn, err := ln.Accept() | |
if err != nil { | |
log.Print(err) | |
continue | |
} | |
buf := make([]byte, 12) | |
n, err := io.ReadFull(conn, buf) | |
if n != len(buf) { | |
log.Printf("has read only %v bytes: %s\n", n, string(buf)) | |
} | |
if string(buf) != "foo\nbar\nbaz\n" { | |
log.Printf("has read something wrong: %s\n", string(buf)) | |
} | |
conn.Close() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment