From 4e6b438d9e058a2ae5224af9978290c91a31b172 Mon Sep 17 00:00:00 2001 From: Marcel Zieba Date: Thu, 11 Apr 2024 18:51:11 +0200 Subject: [PATCH] shared client: add fail-safe mechanism for stuck requests. Signed-off-by: Marcel Zieba --- shared_client.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/shared_client.go b/shared_client.go index 5fc988049..ae1c386a1 100644 --- a/shared_client.go +++ b/shared_client.go @@ -302,8 +302,13 @@ func (c *SharedClient) ExchangeSharedContext(ctx context.Context, m *Msg) (r *Ms } // Since c.requests is unbuffered, the handler is guaranteed to eventually close 'respCh' - resp := <-respCh - return resp.msg, resp.rtt, resp.err + select { + case resp := <-respCh: + return resp.msg, resp.rtt, resp.err + // This is just fail-safe mechanism in case there is another similar issue + case <-time.After(time.Minute): + return nil, 0, fmt.Errorf("timeout waiting for response") + } } // close closes and waits for the close to finish.