Skip to content

Commit d4e13a5

Browse files
xibzaustinvazquez
authored andcommitted
Adding default vsock connection timeout
Prior to this commit, io would be proxied from the VM to the host, but no timeout is provided to the proxy. So if vsock has an issue, the io would forever try to connect to the vsock leading to an extraneous amount of errors. This commit adds a simple default timeout, 5 second, which will eliminate the extraneous amount of logs Signed-off-by: xibz <[email protected]>
1 parent fe7471e commit d4e13a5

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

internal/vm/vsock.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,14 +127,16 @@ func (l vsockListener) Addr() net.Addr {
127127

128128
// VSockDialConnector returns an IOConnector for establishing vsock connections
129129
// that are dialed from the host to a guest listener.
130-
func VSockDialConnector(udsPath string, port uint32) IOConnector {
130+
func VSockDialConnector(timeout time.Duration, udsPath string, port uint32) IOConnector {
131131
return func(procCtx context.Context, logger *logrus.Entry) <-chan IOConnectorResult {
132132
returnCh := make(chan IOConnectorResult)
133133

134134
go func() {
135135
defer close(returnCh)
136+
timeoutCtx, cancel := context.WithTimeout(procCtx, timeout)
137+
defer cancel()
136138

137-
conn, err := VSockDial(procCtx, logger, udsPath, port)
139+
conn, err := VSockDial(timeoutCtx, logger, udsPath, port)
138140
returnCh <- IOConnectorResult{
139141
ReadWriteCloser: conn,
140142
Err: err,

0 commit comments

Comments
 (0)