Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug(sdk/go): http client generates invalid header values #42

Open
tdakkota opened this issue Jun 1, 2023 · 0 comments
Open

bug(sdk/go): http client generates invalid header values #42

tdakkota opened this issue Jun 1, 2023 · 0 comments
Assignees
Labels
bug Something isn't working SDK SDK related

Comments

@tdakkota
Copy link

tdakkota commented Jun 1, 2023

Sending a select_rows command with a placeholder with a binary value leads to a net/http: invalid header field value for "X-Yt-Parameters" error.

It seems YSON text encoder does not escape some characters considered by HTTP as control.

Reproducer
package internal_test

import (
	"context"
	"fmt"
	"testing"

	"go.uber.org/zap/zaptest"
	ytzap "go.ytsaurus.tech/library/go/core/log/zap"
	"go.ytsaurus.tech/yt/go/yson"
	"go.ytsaurus.tech/yt/go/yt"
	"go.ytsaurus.tech/yt/go/yt/ythttp"
)

// placeholderSet is a simple wrapper to encode placeholder values.
//
// See https://github.com/ytsaurus/ytsaurus/blob/bbaedcf016db5e599563bb3f3b5ba87b047b4faa/yt/yt/library/query/base/query_preparer.cpp#L2461.
type placeholderSet struct {
	values []any
}

func (p placeholderSet) MarshalYSON(w *yson.Writer) error {
	w.BeginMap()
	for i, v := range p.values {
		w.MapKeyString(fmt.Sprintf("placeholder%d", i))
		w.Any(v)
	}
	w.EndMap()
	return nil
}

func TestPlaceholders(t *testing.T) {
	ctx := context.Background()

	log := zaptest.NewLogger(t)
	yc, err := ythttp.NewClient(&yt.Config{
		Logger: &ytzap.Logger{L: log},
	})
	if err != nil {
		t.Fatal(err)
	}

	var (
		id = [16]byte{
			0x1f, 0x1f, 0x1f, 0x1f, // <- 0x1f is a control character (unit separator)
			0x1f, 0x1f, 0x1f, 0x1f,
			0x1f, 0x1f, 0x1f, 0x1f,
			0x1f, 0x1f, 0x1f, 0x1f,
		}
		// Table schema does not matter, since query does not actually reach the proxy.
		query        = "* from [//table] where uuid = {placeholder0}"
		placeholders = placeholderSet{
			values: []any{id[:]},
		}
	)

	r, err := yc.SelectRows(ctx, query, &yt.SelectRowsOptions{
		PlaceholderValues: placeholders,
	})
	if err != nil {
		t.Fatal(err)
	}
	defer r.Close()
}
Logs
2023-06-01T21:28:18.836+0300      DEBUG   request started {"call_id": "f4d2888d-b94c52bc-7541d52f-5e7febcf", "method": "select_rows", "query": "* from [//table] where uuid = {placeholder0}"}
2023-06-01T21:28:18.836+0300      DEBUG   sending HTTP request    {"call_id": "f4d2888d-b94c52bc-7541d52f-5e7febcf", "proxy": "localhost:8000"}
2023-06-01T21:28:18.836+0300      WARN    retrying heavy read request     {"call_id": "f4d2888d-b94c52bc-7541d52f-5e7febcf", "backoff": "2.012342203s", "error": "Get \"http://localhost:8000/api/v4/select_rows\": net/http: invalid header field value for \"X-Yt-Parameters\""}
@verytable verytable self-assigned this Jun 14, 2023
@savnadya savnadya added bug Something isn't working SDK SDK related labels Nov 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working SDK SDK related
Projects
None yet
Development

No branches or pull requests

3 participants