Skip to content

Commit fa54478

Browse files
committed
Set basic timeout defaults in cmd/hdfs
1 parent 89f1d88 commit fa54478

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

cmd/hdfs/main.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ package main
33
import (
44
"errors"
55
"fmt"
6+
"net"
67
"os"
8+
"time"
79

810
"github.com/colinmarc/hdfs"
911
"github.com/pborman/getopt"
@@ -199,6 +201,16 @@ func getClient(namenode string) (*hdfs.Client, error) {
199201
}
200202
}
201203

204+
// Set some basic defaults.
205+
dialFunc := (&net.Dialer{
206+
Timeout: 5 * time.Second,
207+
KeepAlive: 5 * time.Second,
208+
DualStack: true,
209+
}).DialContext
210+
211+
options.NamenodeDialFunc = dialFunc
212+
options.DatanodeDialFunc = dialFunc
213+
202214
c, err := hdfs.NewClient(options)
203215
if err != nil {
204216
return nil, fmt.Errorf("Couldn't connect to namenode: %s", err)

0 commit comments

Comments
 (0)