From 4354359aed86b050ff1138e05ec9e782a3c21363 Mon Sep 17 00:00:00 2001 From: Evgenii Stratonikov Date: Tue, 6 Sep 2022 18:23:59 +0300 Subject: [PATCH] [#1746] network: Set timeout for streaming operations Signed-off-by: Evgenii Stratonikov --- cmd/neofs-node/config.go | 5 +++-- cmd/neofs-node/config/apiclient/config.go | 16 ++++++++++++++++ cmd/neofs-node/config/apiclient/config_test.go | 2 ++ config/example/node.env | 1 + config/example/node.json | 3 ++- config/example/node.yaml | 1 + docs/storage-node-configuration.md | 8 +++++--- go.mod | 2 +- go.sum | 6 ++---- pkg/network/cache/client.go | 1 + pkg/network/cache/multi.go | 4 ++++ 11 files changed, 38 insertions(+), 11 deletions(-) diff --git a/cmd/neofs-node/config.go b/cmd/neofs-node/config.go index a95a1a551..087de9a55 100644 --- a/cmd/neofs-node/config.go +++ b/cmd/neofs-node/config.go @@ -323,8 +323,9 @@ func initCfg(path string) *cfg { workerPool: reputationWorkerPool, }, clientCache: cache.NewSDKClientCache(cache.ClientCacheOpts{ - DialTimeout: apiclientconfig.DialTimeout(appCfg), - Key: &key.PrivateKey, + DialTimeout: apiclientconfig.DialTimeout(appCfg), + StreamTimeout: apiclientconfig.StreamTimeout(appCfg), + Key: &key.PrivateKey, }), persistate: persistate, } diff --git a/cmd/neofs-node/config/apiclient/config.go b/cmd/neofs-node/config/apiclient/config.go index 70c36652b..eedad9430 100644 --- a/cmd/neofs-node/config/apiclient/config.go +++ b/cmd/neofs-node/config/apiclient/config.go @@ -11,6 +11,9 @@ const ( // DialTimeoutDefault is a default dial timeout of NeoFS API client connection. 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 @@ -25,3 +28,16 @@ func DialTimeout(c *config.Config) time.Duration { 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 +} diff --git a/cmd/neofs-node/config/apiclient/config_test.go b/cmd/neofs-node/config/apiclient/config_test.go index 85644cb1f..ca77447ed 100644 --- a/cmd/neofs-node/config/apiclient/config_test.go +++ b/cmd/neofs-node/config/apiclient/config_test.go @@ -15,12 +15,14 @@ func TestApiclientSection(t *testing.T) { empty := configtest.EmptyConfig() require.Equal(t, apiclientconfig.DialTimeoutDefault, apiclientconfig.DialTimeout(empty)) + require.Equal(t, apiclientconfig.StreamTimeoutDefault, apiclientconfig.StreamTimeout(empty)) }) const path = "../../../../config/example/node" var fileConfigTest = func(c *config.Config) { require.Equal(t, 15*time.Second, apiclientconfig.DialTimeout(c)) + require.Equal(t, 20*time.Second, apiclientconfig.StreamTimeout(c)) } configtest.ForEachFileType(path, fileConfigTest) diff --git a/config/example/node.env b/config/example/node.env index f93519493..89116388d 100644 --- a/config/example/node.env +++ b/config/example/node.env @@ -69,6 +69,7 @@ NEOFS_MORPH_RPC_ENDPOINT_1_PRIORITY=2 # API Client section NEOFS_APICLIENT_DIAL_TIMEOUT=15s +NEOFS_APICLIENT_STREAM_TIMEOUT=20s # Policer section NEOFS_POLICER_HEAD_TIMEOUT=15s diff --git a/config/example/node.json b/config/example/node.json index b53db4397..34a683650 100644 --- a/config/example/node.json +++ b/config/example/node.json @@ -112,7 +112,8 @@ ] }, "apiclient": { - "dial_timeout": "15s" + "dial_timeout": "15s", + "stream_timeout": "20s" }, "policer": { "head_timeout": "15s" diff --git a/config/example/node.yaml b/config/example/node.yaml index c7b3b1e76..e6bc7ec30 100644 --- a/config/example/node.yaml +++ b/config/example/node.yaml @@ -91,6 +91,7 @@ morph: apiclient: dial_timeout: 15s # timeout for NEOFS API client connection + stream_timeout: 20s # timeout for individual operations in a streaming RPC policer: head_timeout: 15s # timeout for the Policer HEAD remote operation diff --git a/docs/storage-node-configuration.md b/docs/storage-node-configuration.md index 1139e83a2..10d045156 100644 --- a/docs/storage-node-configuration.md +++ b/docs/storage-node-configuration.md @@ -366,10 +366,12 @@ Configuration for the NeoFS API client used for communication with other NeoFS n ```yaml apiclient: dial_timeout: 15s + stream_timeout: 20s ``` -| Parameter | Type | Default value | Description | -|--------------|----------|---------------|-----------------------------------------------------------------------| -| dial_timeout | duration | `5s` | Timeout for dialing connections to other storage or inner ring nodes. | +| Parameter | Type | Default value | Description | +|----------------|----------|---------------|-----------------------------------------------------------------------| +| 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 diff --git a/go.mod b/go.mod index fd755252e..7aa131e8d 100644 --- a/go.mod +++ b/go.mod @@ -19,7 +19,7 @@ require ( 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-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/panjf2000/ants/v2 v2.4.0 github.com/paulmach/orb v0.2.2 diff --git a/go.sum b/go.sum index cd30969ef..2fb0887c7 100644 --- a/go.sum +++ b/go.sum @@ -445,11 +445,9 @@ github.com/nspcc-dev/hrw v1.0.9/go.mod h1:l/W2vx83vMQo6aStyx2AuZrJ+07lGv2JQGlVkP github.com/nspcc-dev/neo-go v0.73.1-pre.0.20200303142215-f5a1b928ce09/go.mod h1:pPYwPZ2ks+uMnlRLUyXOpLieaDQSEaf4NM3zHVbRjmg= github.com/nspcc-dev/neo-go v0.98.0/go.mod h1:E3cc1x6RXSXrJb2nDWXTXjnXk3rIqVN8YdFyWv+FrqM= github.com/nspcc-dev/neo-go v0.99.1-pre.0.20220714084516-54849ef3e58e/go.mod h1:/y5Sl8p3YheTygriBtCCMWKkDOek8HcvSo5ds2rJtKI= -github.com/nspcc-dev/neo-go v0.99.1/go.mod h1:wvKMQXlE/M3eqtN0KIi1MjkEVTvYIJRrOMnJtqEkCxs= github.com/nspcc-dev/neo-go v0.99.2 h1:Fq79FI6BJkj/XkgWtrURSdXgXIeBHCgbKauBw3LOvZ4= github.com/nspcc-dev/neo-go v0.99.2/go.mod h1:9P0yWqhZX7i/ChJ+zjtiStO1uPTolPFUM+L5oNznU8E= github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20220713145417-4f184498bc42/go.mod h1:QBE0I30F2kOAISNpT5oks82yF4wkkUq3SCfI3Hqgx/Y= -github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20220727202624-6c7a401f776a/go.mod h1:QBE0I30F2kOAISNpT5oks82yF4wkkUq3SCfI3Hqgx/Y= github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20220809123759-3094d3e0c14b h1:J7QZNmnO84esVuPbBo88fwAG4XVnDjlSTiO1ewLNCkQ= github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20220809123759-3094d3e0c14b/go.mod h1:23bBw0v6pBYcrWs8CBEEDIEDJNbcFoIh8pGGcf2Vv8s= github.com/nspcc-dev/neofs-api-go/v2 v2.11.0-pre.0.20211201134523-3604d96f3fe1/go.mod h1:oS8dycEh8PPf2Jjp6+8dlwWyEv2Dy77h/XhhcdxYEFs= @@ -466,8 +464,8 @@ github.com/nspcc-dev/neofs-crypto v0.4.0 h1:5LlrUAM5O0k1+sH/sktBtrgfWtq1pgpDs09f github.com/nspcc-dev/neofs-crypto v0.4.0/go.mod h1:6XJ8kbXgOfevbI2WMruOtI+qUJXNwSGM/E9eClXxPHs= github.com/nspcc-dev/neofs-sdk-go v0.0.0-20211201182451-a5b61c4f6477/go.mod h1:dfMtQWmBHYpl9Dez23TGtIUKiFvCIxUZq/CkSIhEpz4= github.com/nspcc-dev/neofs-sdk-go v0.0.0-20220113123743-7f3162110659/go.mod h1:/jay1lr3w7NQd/VDBkEhkJmDmyPNsu4W+QV2obsUV40= -github.com/nspcc-dev/neofs-sdk-go v1.0.0-rc.6.0.20220829114550-ee92df32032e h1:4bw+na7QGjEHnZeNGhW31+l/MQ6N5NZ1LxCbldY0Rgo= -github.com/nspcc-dev/neofs-sdk-go v1.0.0-rc.6.0.20220829114550-ee92df32032e/go.mod h1:zANAq4ZCA1YFX+DSzP/ydBv/Krj5sdkK5orpTISmZR4= +github.com/nspcc-dev/neofs-sdk-go v1.0.0-rc.6.0.20220907075128-43a57d42dd50 h1:fEyKNl9p0tKcVx7MDsSgGNxyZcNQzfU3v/5pL6uE1bs= +github.com/nspcc-dev/neofs-sdk-go v1.0.0-rc.6.0.20220907075128-43a57d42dd50/go.mod h1:+p9n6aUd54L+TsFdYmFxNPPyjMmSbVEf6l2uHU5TLbo= github.com/nspcc-dev/rfc6979 v0.1.0/go.mod h1:exhIh1PdpDC5vQmyEsGvc4YDM/lyQp/452QxGq/UEso= github.com/nspcc-dev/rfc6979 v0.2.0 h1:3e1WNxrN60/6N0DW7+UYisLeZJyfqZTNOjeV/toYvOE= github.com/nspcc-dev/rfc6979 v0.2.0/go.mod h1:exhIh1PdpDC5vQmyEsGvc4YDM/lyQp/452QxGq/UEso= diff --git a/pkg/network/cache/client.go b/pkg/network/cache/client.go index 598f43528..027e90a4b 100644 --- a/pkg/network/cache/client.go +++ b/pkg/network/cache/client.go @@ -20,6 +20,7 @@ type ( ClientCacheOpts struct { DialTimeout time.Duration + StreamTimeout time.Duration Key *ecdsa.PrivateKey ResponseCallback func(client.ResponseMetaInfo) error } diff --git a/pkg/network/cache/multi.go b/pkg/network/cache/multi.go index 10c579810..2bb824796 100644 --- a/pkg/network/cache/multi.go +++ b/pkg/network/cache/multi.go @@ -47,6 +47,10 @@ func (x *multiClient) createForAddress(addr network.Address) clientcore.Client { prmDial.SetTimeout(x.opts.DialTimeout) } + if x.opts.StreamTimeout > 0 { + prmDial.SetStreamTimeout(x.opts.StreamTimeout) + } + if x.opts.ResponseCallback != nil { prmInit.SetResponseInfoCallback(x.opts.ResponseCallback) }