[#1746] network: Set timeout for streaming operations

Signed-off-by: Evgenii Stratonikov <evgeniy@morphbits.ru>
This commit is contained in:
Evgenii Stratonikov 2022-09-06 18:23:59 +03:00 committed by LeL
parent 0140ac354b
commit 4354359aed
11 changed files with 36 additions and 7 deletions

View file

@ -323,8 +323,9 @@ func initCfg(path string) *cfg {
workerPool: reputationWorkerPool, workerPool: reputationWorkerPool,
}, },
clientCache: cache.NewSDKClientCache(cache.ClientCacheOpts{ clientCache: cache.NewSDKClientCache(cache.ClientCacheOpts{
DialTimeout: apiclientconfig.DialTimeout(appCfg), DialTimeout: apiclientconfig.DialTimeout(appCfg),
Key: &key.PrivateKey, StreamTimeout: apiclientconfig.StreamTimeout(appCfg),
Key: &key.PrivateKey,
}), }),
persistate: persistate, persistate: persistate,
} }

View file

@ -11,6 +11,9 @@ const (
// DialTimeoutDefault is a default dial timeout of NeoFS API client connection. // DialTimeoutDefault is a default dial timeout of NeoFS API client connection.
DialTimeoutDefault = 5 * time.Second DialTimeoutDefault = 5 * time.Second
// StreamTimeoutDefault is a default timeout of NeoFS API streaming operation.
StreamTimeoutDefault = 15 * time.Second
) )
// DialTimeout returns the value of "dial_timeout" config parameter // DialTimeout returns the value of "dial_timeout" config parameter
@ -25,3 +28,16 @@ func DialTimeout(c *config.Config) time.Duration {
return DialTimeoutDefault return DialTimeoutDefault
} }
// StreamTimeout returns the value of "stream_timeout" config parameter
// from "apiclient" section.
//
// Returns DialTimeoutDefault if the value is not positive duration.
func StreamTimeout(c *config.Config) time.Duration {
v := config.DurationSafe(c.Sub(subsection), "stream_timeout")
if v > 0 {
return v
}
return StreamTimeoutDefault
}

View file

@ -15,12 +15,14 @@ func TestApiclientSection(t *testing.T) {
empty := configtest.EmptyConfig() empty := configtest.EmptyConfig()
require.Equal(t, apiclientconfig.DialTimeoutDefault, apiclientconfig.DialTimeout(empty)) require.Equal(t, apiclientconfig.DialTimeoutDefault, apiclientconfig.DialTimeout(empty))
require.Equal(t, apiclientconfig.StreamTimeoutDefault, apiclientconfig.StreamTimeout(empty))
}) })
const path = "../../../../config/example/node" const path = "../../../../config/example/node"
var fileConfigTest = func(c *config.Config) { var fileConfigTest = func(c *config.Config) {
require.Equal(t, 15*time.Second, apiclientconfig.DialTimeout(c)) require.Equal(t, 15*time.Second, apiclientconfig.DialTimeout(c))
require.Equal(t, 20*time.Second, apiclientconfig.StreamTimeout(c))
} }
configtest.ForEachFileType(path, fileConfigTest) configtest.ForEachFileType(path, fileConfigTest)

View file

@ -69,6 +69,7 @@ NEOFS_MORPH_RPC_ENDPOINT_1_PRIORITY=2
# API Client section # API Client section
NEOFS_APICLIENT_DIAL_TIMEOUT=15s NEOFS_APICLIENT_DIAL_TIMEOUT=15s
NEOFS_APICLIENT_STREAM_TIMEOUT=20s
# Policer section # Policer section
NEOFS_POLICER_HEAD_TIMEOUT=15s NEOFS_POLICER_HEAD_TIMEOUT=15s

View file

@ -112,7 +112,8 @@
] ]
}, },
"apiclient": { "apiclient": {
"dial_timeout": "15s" "dial_timeout": "15s",
"stream_timeout": "20s"
}, },
"policer": { "policer": {
"head_timeout": "15s" "head_timeout": "15s"

View file

@ -91,6 +91,7 @@ morph:
apiclient: apiclient:
dial_timeout: 15s # timeout for NEOFS API client connection dial_timeout: 15s # timeout for NEOFS API client connection
stream_timeout: 20s # timeout for individual operations in a streaming RPC
policer: policer:
head_timeout: 15s # timeout for the Policer HEAD remote operation head_timeout: 15s # timeout for the Policer HEAD remote operation

View file

@ -366,10 +366,12 @@ Configuration for the NeoFS API client used for communication with other NeoFS n
```yaml ```yaml
apiclient: apiclient:
dial_timeout: 15s dial_timeout: 15s
stream_timeout: 20s
``` ```
| Parameter | Type | Default value | Description | | Parameter | Type | Default value | Description |
|--------------|----------|---------------|-----------------------------------------------------------------------| |----------------|----------|---------------|-----------------------------------------------------------------------|
| dial_timeout | duration | `5s` | Timeout for dialing connections to other storage or inner ring nodes. | | dial_timeout | duration | `5s` | Timeout for dialing connections to other storage or inner ring nodes. |
| stream_timeout | duration | `15s` | Timeout for individual operations in a streaming RPC. |
# `policer` section # `policer` section

2
go.mod
View file

@ -19,7 +19,7 @@ require (
github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20220809123759-3094d3e0c14b // indirect github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20220809123759-3094d3e0c14b // indirect
github.com/nspcc-dev/neofs-api-go/v2 v2.13.2-0.20220827080658-9e17cdfc7647 github.com/nspcc-dev/neofs-api-go/v2 v2.13.2-0.20220827080658-9e17cdfc7647
github.com/nspcc-dev/neofs-contract v0.15.5 github.com/nspcc-dev/neofs-contract v0.15.5
github.com/nspcc-dev/neofs-sdk-go v1.0.0-rc.6.0.20220829114550-ee92df32032e github.com/nspcc-dev/neofs-sdk-go v1.0.0-rc.6.0.20220907075128-43a57d42dd50
github.com/nspcc-dev/tzhash v1.6.1 github.com/nspcc-dev/tzhash v1.6.1
github.com/panjf2000/ants/v2 v2.4.0 github.com/panjf2000/ants/v2 v2.4.0
github.com/paulmach/orb v0.2.2 github.com/paulmach/orb v0.2.2

BIN
go.sum

Binary file not shown.

View file

@ -20,6 +20,7 @@ type (
ClientCacheOpts struct { ClientCacheOpts struct {
DialTimeout time.Duration DialTimeout time.Duration
StreamTimeout time.Duration
Key *ecdsa.PrivateKey Key *ecdsa.PrivateKey
ResponseCallback func(client.ResponseMetaInfo) error ResponseCallback func(client.ResponseMetaInfo) error
} }

View file

@ -47,6 +47,10 @@ func (x *multiClient) createForAddress(addr network.Address) clientcore.Client {
prmDial.SetTimeout(x.opts.DialTimeout) prmDial.SetTimeout(x.opts.DialTimeout)
} }
if x.opts.StreamTimeout > 0 {
prmDial.SetStreamTimeout(x.opts.StreamTimeout)
}
if x.opts.ResponseCallback != nil { if x.opts.ResponseCallback != nil {
prmInit.SetResponseInfoCallback(x.opts.ResponseCallback) prmInit.SetResponseInfoCallback(x.opts.ResponseCallback)
} }