Skip to content

ClickHouse Instrumentation inadvertently changes application code pathΒ #13019

@cleverchuk

Description

@cleverchuk

Describe the bug

Execution of this line of code causes ClickHouse syntax error for queries of the form select * from table where s={s:String}. When that line is executed, it causes subsequent application code execution to follow a different code path which results in the error observed. There are two code paths to follow, this and this. When the first path is followed, the code executes normally and fails when the second path is followed due to the execution of this making preparedQuery not null.

Steps to reproduce

Add below test to ClickHouseClientTest

    @Test
    void testPlaceholderQueryInput() throws Exception {
        ClickHouseRequest<?> request = client.read(server).format(ClickHouseFormat.RowBinaryWithNamesAndTypes);
        testing.runWithSpan(
                "parent",
                () -> {
                    ClickHouseResponse response =
                            request
                                    .query("select * from " + tableName + " where s={s:String}")
                                    .settings(ImmutableMap.of("param_s", "" + Instant.now().getEpochSecond()))
                                    .execute().get();
                    response.close();

                });

        testing.waitAndAssertTraces(
                trace ->
                        trace.hasSpansSatisfyingExactly(
                                span -> span.hasName("parent").hasNoParent().hasAttributes(Attributes.empty()),
                                span ->
                                        span.hasName("SELECT " + dbName)
                                                .hasKind(SpanKind.CLIENT)
                                                .hasParent(trace.getSpan(0))
                                                .hasAttributesSatisfyingExactly(
                                                        attributeAssertions(
                                                                "select * from " + tableName + " where s={s:String}", "SELECT"))));
    }

Expected behavior

No syntax error

Actual behavior

Syntax error

Caused by: java.io.IOException: Code: 62. DB::Exception: Syntax error: failed at position 40 ('}'): }. Expected colon between name and type. (SYNTAX_ERROR) (version 24.4.2.141 (official build))

	at com.clickhouse.client.http.ApacheHttpConnectionImpl.checkResponse(ApacheHttpConnectionImpl.java:209)
	at com.clickhouse.client.http.ApacheHttpConnectionImpl.post(ApacheHttpConnectionImpl.java:243)
	at com.clickhouse.client.http.ClickHouseHttpClient.send(ClickHouseHttpClient.java:118)
	at com.clickhouse.client.AbstractClient.sendAsync(AbstractClient.java:161)
	at com.clickhouse.client.AbstractClient.lambda$execute$0(AbstractClient.java:273)
	... 98 more

Javaagent or library instrumentation version

2.9.0

Environment

JDK: openjdk 17.0.7
OS: OSX 24.2.0

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions