Skip to content

Commit

Permalink
Support setting response header timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
duanliguo committed Mar 12, 2024
1 parent 90be1c2 commit e796d44
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 4 deletions.
2 changes: 1 addition & 1 deletion bce/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import (

// Constants and default values for the package bce
const (
SDK_VERSION = "0.9.168"
SDK_VERSION = "0.9.169"
URI_PREFIX = "/" // now support uri without prefix "v1" so just set root path
DEFAULT_DOMAIN = "baidubce.com"
DEFAULT_PROTOCOL = "http"
Expand Down
19 changes: 19 additions & 0 deletions http/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,3 +172,22 @@ func Execute(request *Request) (*Response, error) {
response := &Response{httpResponse, end.Sub(start)}
return response, nil
}
func SetResponseHeaderTimeout(t int) {
transport = &http.Transport{
MaxIdleConnsPerHost: defaultMaxIdleConnsPerHost,
ResponseHeaderTimeout: time.Duration(t) * time.Second,
Dial: func(network, address string) (net.Conn, error) {
conn, err := net.DialTimeout(network, address, defaultDialTimeout)
if err != nil {
return nil, err
}
tc := &timeoutConn{conn, defaultSmallInterval, defaultLargeInterval}
err = tc.SetReadDeadline(time.Now().Add(defaultLargeInterval))
if err != nil {
return nil, err
}
return tc, nil
},
}
httpClient.Transport = transport
}
1 change: 1 addition & 0 deletions services/cfc/api/cfc.go
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,7 @@ func Invocations(cli bce.Client, args *InvocationsArgs) (*InvocationsResult, err
}

req := &bce.BceRequest{}
http.SetResponseHeaderTimeout(DefaultMaxFunctionTimeout)
req.SetRequestId(args.RequestId)
req.SetUri(getInvocationsUri(args.FunctionName))
req.SetMethod(http.POST)
Expand Down
2 changes: 2 additions & 0 deletions services/cfc/api/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ const (
InvocationTypeEvent InvocationType = "Event"
InvocationTypeRequestResponse InvocationType = "RequestResponse"
InvocationTypeDryRun InvocationType = "DryRun"
// 同步调用函数最大超时时间
DefaultMaxFunctionTimeout = 300

LogTypeTail LogType = "Tail"
LogTypeNone LogType = "None"
Expand Down
6 changes: 3 additions & 3 deletions services/scs/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ type UpdateInstanceNameArgs struct {
}

type NodeType struct {
InstanceFlavor int `json:"instanceFlavor"`
InstanceFlavor float64 `json:"instanceFlavor"`
NodeType string `json:"nodeType"`
CPUNum int `json:"cpuNum"`
NetworkThroughputInGbps float64 `json:"networkThroughputInGbps"`
Expand Down Expand Up @@ -596,7 +596,7 @@ type GroupLeaderInfo struct {
TotalCapacityInGB float64 `json:"totalCapacityInGB"`
UsedCapacityInGB int `json:"usedCapacityInGB"`
ShardNum int `json:"shardNum"`
Flavor int `json:"flavor"`
Flavor float64 `json:"flavor"`
QpsWrite int64 `json:"qpsWrite"`
QpsRead int64 `json:"qpsRead"`
StableReadable bool `json:"stableReadable"`
Expand All @@ -612,7 +612,7 @@ type GroupFollowerInfo struct {
TotalCapacityInGB float64 `json:"totalCapacityInGB"`
UsedCapacityInGB int `json:"usedCapacityInGB"`
ShardNum int `json:"shardNum"`
Flavor int `json:"flavor"`
Flavor float64 `json:"flavor"`
QpsWrite int64 `json:"qpsWrite"`
QpsRead int64 `json:"qpsRead"`
StableReadable bool `json:"stableReadable"`
Expand Down

0 comments on commit e796d44

Please sign in to comment.