From 4c8f9580a16eb5d30320d670849585fe25c1d04d Mon Sep 17 00:00:00 2001
From: Airat Arifullin <a.arifullin@yadro.com>
Date: Wed, 5 Mar 2025 17:09:02 +0300
Subject: [PATCH] [#1662] object: Fix `CloseAndRecv` for patch streamer

* A client may open stream to server, not send anything and close
  the open stream immediatly. This shouldn't cause a panic;
* Return the error if `s.patcher` is uninitialized. Uninitialized
  patcher cannot be closed, this causes a panic.

Signed-off-by: Airat Arifullin <a.arifullin@yadro.com>
---
 pkg/services/object/patch/streamer.go | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/pkg/services/object/patch/streamer.go b/pkg/services/object/patch/streamer.go
index 5aba13f6..642b9f9f 100644
--- a/pkg/services/object/patch/streamer.go
+++ b/pkg/services/object/patch/streamer.go
@@ -214,6 +214,9 @@ func (s *Streamer) Send(ctx context.Context, req *objectV2.PatchRequest) error {
 }
 
 func (s *Streamer) CloseAndRecv(ctx context.Context) (*objectV2.PatchResponse, error) {
+	if s.patcher == nil {
+		return nil, errors.New("uninitialized patch streamer")
+	}
 	patcherResp, err := s.patcher.Close(ctx)
 	if err != nil {
 		return nil, err