From 8156737b50e15f90c8866029982338e3380b1b22 Mon Sep 17 00:00:00 2001 From: Piotr Jastrzebski Date: Wed, 15 Nov 2023 13:25:27 +0100 Subject: [PATCH] Close stream in hranaV2Conn.Close Signed-off-by: Piotr Jastrzebski --- libsql/internal/http/hranaV2/hranaV2.go | 24 +++++++----------------- 1 file changed, 7 insertions(+), 17 deletions(-) diff --git a/libsql/internal/http/hranaV2/hranaV2.go b/libsql/internal/http/hranaV2/hranaV2.go index 41c7a3c..32ce1f8 100644 --- a/libsql/internal/http/hranaV2/hranaV2.go +++ b/libsql/internal/http/hranaV2/hranaV2.go @@ -88,6 +88,13 @@ func (h *hranaV2Conn) PrepareContext(ctx context.Context, query string) (driver. } func (h *hranaV2Conn) Close() error { + if h.baton != "" { + go func(baton, url, jwt, host string) { + msg := hrana.PipelineRequest{Baton: baton} + msg.Add(hrana.CloseStream()) + _, _, _ = sendPipelineRequest(context.Background(), &msg, url, jwt, host) + }(h.baton, h.url, h.jwt, h.host) + } return nil } @@ -378,23 +385,6 @@ func (h *hranaV2Conn) QueryContext(ctx context.Context, query string, args []dri } } -func (h *hranaV2Conn) closeStream(ctx context.Context) error { - msg := &hrana.PipelineRequest{} - msg.Add(hrana.CloseStream()) - result, err := h.sendPipelineRequest(ctx, msg, true) - if err != nil { - return fmt.Errorf("failed to close stream: %w", err) - } - - if result.Results[0].Error != nil { - return fmt.Errorf("failed to close stream: %s", result.Results[0].Error.Message) - } - if result.Results[0].Response == nil { - return errors.New("failed to close stream: no response received") - } - return nil -} - func (h *hranaV2Conn) ResetSession(ctx context.Context) error { if h.baton != "" { go func(baton, url, jwt, host string) {