From 43a57d42dd50dc60465bfd3482f7f12bcfcf3411 Mon Sep 17 00:00:00 2001 From: Evgenii Stratonikov Date: Tue, 6 Sep 2022 18:17:54 +0300 Subject: [PATCH] [#331] client: Allow to set timeout for streaming operations Signed-off-by: Evgenii Stratonikov --- client/client.go | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/client/client.go b/client/client.go index 655fa934..dea80c11 100644 --- a/client/client.go +++ b/client/client.go @@ -80,9 +80,18 @@ func (c *Client) Dial(prm PrmDial) error { prm.timeoutDial = 5 * time.Second } + if prm.streamTimeoutSet { + if prm.streamTimeout <= 0 { + panic("non-positive timeout") + } + } else { + prm.streamTimeout = 10 * time.Second + } + c.c = *client.New(append( client.WithNetworkURIAddress(prm.endpoint, prm.tlsConfig), client.WithDialTimeout(prm.timeoutDial), + client.WithRWTimeout(prm.streamTimeout), )...) // TODO: (neofs-api-go#382) perform generic dial stage of the client.Client @@ -149,6 +158,9 @@ type PrmDial struct { timeoutDialSet bool timeoutDial time.Duration + + streamTimeoutSet bool + streamTimeout time.Duration } // SetServerURI sets server URI in the NeoFS network. @@ -182,3 +194,10 @@ func (x *PrmDial) SetTimeout(timeout time.Duration) { x.timeoutDialSet = true x.timeoutDial = timeout } + +// SetStreamTimeout sets the timeout for individual operations in streaming RPC. +// MUST BE positive. If not called, 10s timeout will be used by default. +func (x *PrmDial) SetStreamTimeout(timeout time.Duration) { + x.streamTimeoutSet = true + x.streamTimeout = timeout +}