Skip to content

Commit ce293b9

Browse files
committed
Retry Recvfrom if observing EINTR
It appears this similar pattern is done elsewhere in libcontainer. Unsure if it needs to be do everywhere unix. is used directly or not. Signed-off-by: Evan Phoenix <[email protected]>
1 parent 91e6621 commit ce293b9

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

libcontainer/sync_unix.go

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package libcontainer
22

33
import (
4+
"errors"
45
"fmt"
56
"io"
67
"os"
@@ -42,8 +43,21 @@ func (s *syncSocket) WritePacket(b []byte) (int, error) {
4243
}
4344

4445
func (s *syncSocket) ReadPacket() ([]byte, error) {
45-
size, _, err := unix.Recvfrom(int(s.f.Fd()), nil, unix.MSG_TRUNC|unix.MSG_PEEK)
46-
if err != nil {
46+
var (
47+
size int
48+
err error
49+
)
50+
51+
for {
52+
size, _, err = unix.Recvfrom(int(s.f.Fd()), nil, unix.MSG_TRUNC|unix.MSG_PEEK)
53+
if err == nil {
54+
break
55+
}
56+
57+
if errors.Is(err, unix.EINTR) {
58+
continue
59+
}
60+
4761
return nil, fmt.Errorf("fetch packet length from socket: %w", err)
4862
}
4963
// We will only get a zero size if the socket has been closed from the

0 commit comments

Comments
 (0)