Closed winlinvip closed 7 years ago
端口池分配的逻辑感觉有点问题:
// Check if a port is available
func Check(port int) (status bool, err error) {
// Concatenate a colon and the port
host := ":" + strconv.Itoa(port)
// Try to create a server with the port
server, err := net.Listen("tcp", host)
// if it fails then the port is likely taken
if err != nil {
return false, err
}
// close the server
server.Close()
// we successfully used and closed the port
// so it's now available to be used again
return true, nil
}
这段代码不知道行不行, 没找到更好方法.
如果port占用,应该再次分配,你提pr吧。
@winlinvip OK, 我试试.
When shell allocate port, the port maybe listened by other processes, we should check it, ignore the unavailable port.