This is racy. Another process could swoop in and steal the port between the call to this function and the next listen call. Should be okay though. The proper way would be to pass the l.File() as ExtraFiles to the child process, and then close your copy once the child starts.
(t *testing.T)
| 131 | // The proper way would be to pass the l.File() as ExtraFiles to the child |
| 132 | // process, and then close your copy once the child starts. |
| 133 | func pickFreeAddr(t *testing.T) string { |
| 134 | l, err := net.Listen("tcp", "127.0.0.1:0") |
| 135 | if err != nil { |
| 136 | t.Fatal(err) |
| 137 | } |
| 138 | defer l.Close() |
| 139 | return l.Addr().String() |
| 140 | } |
| 141 | |
| 142 | func addrToURL(addr []string) []string { |
| 143 | url := make([]string, len(addr)) |
no test coverage detected
searching dependent graphs…