Skip to content

Commit

Permalink
Merge pull request #20641 from jakecorrenti/socket-mapping-nits
Browse files Browse the repository at this point in the history
Fix socket mapping nits
  • Loading branch information
openshift-merge-bot[bot] authored Nov 9, 2023
2 parents d7d8b86 + 39d647a commit 4a20de7
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 24 deletions.
12 changes: 1 addition & 11 deletions pkg/machine/applehv/machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -669,24 +669,14 @@ func (m *MacMachine) Start(name string, opts machine.StartOptions) error {
}

logrus.Debug("waiting for ready notification")
var conn net.Conn
readyChan := make(chan error)
connChan := make(chan net.Conn)
go machine.ListenAndWaitOnSocket(readyChan, connChan, readyListen)
go machine.ListenAndWaitOnSocket(readyChan, readyListen)

if err := cmd.Start(); err != nil {
return err
}

err = <-readyChan
conn = <-connChan
if conn != nil {
defer func() {
if closeErr := conn.Close(); closeErr != nil {
logrus.Error(closeErr)
}
}()
}
if err != nil {
return err
}
Expand Down
11 changes: 1 addition & 10 deletions pkg/machine/hyperv/vsock.go
Original file line number Diff line number Diff line change
Expand Up @@ -274,16 +274,7 @@ func (hv *HVSockRegistryEntry) Listen() error {
}()

errChan := make(chan error)
connChan := make(chan net.Conn)
go machine.ListenAndWaitOnSocket(errChan, connChan, listener)
conn := <-connChan
go machine.ListenAndWaitOnSocket(errChan, listener)

if conn != nil {
defer func() {
if err := conn.Close(); err != nil {
logrus.Error(err)
}
}()
}
return <-errChan
}
10 changes: 7 additions & 3 deletions pkg/machine/sockets.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,20 @@ func ReadySocketPath(runtimeDir, machineName string) string {
// ListenAndWaitOnSocket waits for a new connection to the listener and sends
// any error back through the channel. ListenAndWaitOnSocket is intended to be
// used as a goroutine
func ListenAndWaitOnSocket(errChan chan<- error, connChan chan<- net.Conn, listener net.Listener) {
func ListenAndWaitOnSocket(errChan chan<- error, listener net.Listener) {
conn, err := listener.Accept()
if err != nil {
errChan <- err
connChan <- nil
return
}
_, err = bufio.NewReader(conn).ReadString('\n')

if closeErr := conn.Close(); closeErr != nil {
errChan <- closeErr
return
}

errChan <- err
connChan <- conn
}

// DialSocketWithBackoffs attempts to connect to the socket in maxBackoffs attempts
Expand Down

0 comments on commit 4a20de7

Please sign in to comment.