Skip to content
This repository has been archived by the owner on May 12, 2021. It is now read-only.

Commit

Permalink
FC: Add new vsock connection handshake
Browse files Browse the repository at this point in the history
New Firecracker v0.20.0 has changed the host-initiated vsock
connection protocol to include a trivial handshake.

The new protocol looks like this:
- [host] CONNECT <port><LF>
- [guest/success] OK <assigned_host_port><LF>

Fixes: #705

Signed-off-by: Penny Zheng <[email protected]>
  • Loading branch information
Pennyzct committed Jan 30, 2020
1 parent fc8bfb4 commit a44d555
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions protocols/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
package client

import (
"bufio"
"context"
"fmt"
"net"
Expand Down Expand Up @@ -407,12 +408,19 @@ func HybridVSockDialer(sock string, timeout time.Duration) (net.Conn, error) {
return nil, err
}

// Read EOT (End of transmission) byte
eot := make([]byte, 32)
if _, err = conn.Read(eot); err != nil {
// Just close the connection, gRPC will dial again
// without errors
// A trivial handshake is included in the host-initiated vsock connection protocol.
// It looks like this:
// - [host] CONNECT <port><LF>
// - [guest/success] OK <assigned_host_port><LF>
reader := bufio.NewReader(conn)
if response, err := reader.ReadString('\n'); err != nil {
conn.Close()
// for now, we temporarily rely on the backoff strategy from GRPC for more stable CI.
return conn, nil
} else if !strings.Contains(response, "OK") {
conn.Close()
// for now, we temporarily rely on the backoff strategy from GRPC for more stable CI.
return conn, nil
}

return conn, nil
Expand Down

0 comments on commit a44d555

Please sign in to comment.