Skip to content

Commit

Permalink
BUG/MEDIUM: Set timeout to socket operations
Browse files Browse the repository at this point in the history
No deadline were set on the socket connection, potentially causing
operations to hang forever. This in turn prevents to queue new tasks.
We now set a 30s timeout to socket operations (dial, read, write).
  • Loading branch information
ShimmerGlass authored and mjuraga committed Mar 30, 2021
1 parent efed5c7 commit ecb938d
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions runtime/runtime_single_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ import (
"time"
)

const (
taskTimeout = 30 * time.Second
)

// TaskResponse ...
type TaskResponse struct {
result string
Expand Down Expand Up @@ -70,12 +74,15 @@ func (s *SingleRuntime) readFromSocket(command string) (string, error) {
var api net.Conn
var err error

if api, err = net.Dial("unix", s.socketPath); err != nil {
if api, err = net.DialTimeout("unix", s.socketPath, taskTimeout); err != nil {
return "", err
}
defer func() {
_ = api.Close()
}()
if err = api.SetDeadline(time.Now().Add(taskTimeout)); err != nil {
return "", err
}

fullCommand := fmt.Sprintf("set severity-output number;%s\n", command)
if s.worker > 0 {
Expand Down Expand Up @@ -158,7 +165,7 @@ func (s *SingleRuntime) executeRaw(command string, retry int) (string, error) {
return s.executeRaw(command, retry)
}
return rsp.result, rsp.err
case <-time.After(time.Duration(30) * time.Second):
case <-time.After(taskTimeout):
return "", fmt.Errorf("timeout reached")
}
}

0 comments on commit ecb938d

Please sign in to comment.