Skip to content

Commit f644ae7

Browse files
committed
fixup! fix: cannot start container when IPv6 is disabled
Move ErrNotExist handling from procnet.ReadStatsFileData to getUsedPorts, so that the caller expresses the intent to ignore missing IPv6 stats files rather than the general-purpose helper. Signed-off-by: Shouhei <shouhei.yamaguchi.be@gmail.com>
1 parent 4fc465e commit f644ae7

File tree

2 files changed

+4
-7
lines changed

2 files changed

+4
-7
lines changed

pkg/portutil/port_allocate_linux.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@
1717
package portutil
1818

1919
import (
20+
"errors"
2021
"fmt"
22+
"os"
2123

2224
"github.com/containerd/nerdctl/v2/pkg/portutil/iptable"
2325
"github.com/containerd/nerdctl/v2/pkg/portutil/procnet"
@@ -86,14 +88,14 @@ func getUsedPorts(ip string, protocol string) (map[uint64]bool, error) {
8688
// So we need some trick to process this situation.
8789
if protocol == "tcp" {
8890
tempTCPV6Data, err := procnet.ReadStatsFileData("tcp6")
89-
if err != nil {
91+
if err != nil && !errors.Is(err, os.ErrNotExist) {
9092
return nil, err
9193
}
9294
netprocItems = append(netprocItems, procnet.Parse(tempTCPV6Data)...)
9395
}
9496
if protocol == "udp" {
9597
tempUDPV6Data, err := procnet.ReadStatsFileData("udp6")
96-
if err != nil {
98+
if err != nil && !errors.Is(err, os.ErrNotExist) {
9799
return nil, err
98100
}
99101
netprocItems = append(netprocItems, procnet.Parse(tempUDPV6Data)...)

pkg/portutil/procnet/procnet_linux.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ package procnet
1818

1919
import (
2020
"bufio"
21-
"errors"
2221
"fmt"
2322
"os"
2423
)
@@ -53,10 +52,6 @@ func ReadStatsFileData(protocol string) ([]string, error) {
5352

5453
fp, err := os.Open(fileAddress)
5554
if err != nil {
56-
// IPv6-disabled environments do not have these files.
57-
if (fileAddress == netTCP6Stats || fileAddress == netUDP6Stats) && errors.Is(err, os.ErrNotExist) {
58-
return nil, nil
59-
}
6055
return nil, err
6156
}
6257
defer fp.Close()

0 commit comments

Comments
 (0)