Skip to content

R2DBC client: ClickHouseResult map implementation logs but doesn't propagate exceptions. #1819

Open

Description

@andrescrz

Describe the bug

For the R2DBC client, in ClickHouseResult class, the map method implementation logs but doesn't propagate exceptions. However, in the same class the flatMap method implementation both logs and propagates exceptions. See code:

Steps to reproduce

  1. Execute any statement producing aResult object.
  2. Any error triggered within the biFunction argument passed to map will be logged but not propagated. For instance, just throw a new IllegalArgumentException.
  3. Exception is logged but not propagated.

Expected behaviour

Unpropagated exceptions highly increases the chances of errors being unnoticed, unless logs are observed or analysed.

The expected behaviour is propagating the exception, like flatMap method does.

Code example

import io.r2dbc.spi.ConnectionFactory;
import reactor.core.publisher.Mono;

public class ClickHouseRepository {

    ConnectionFactory connectionFactory;

    Mono<Void> example() {
        return Mono.from(connectionFactory.create())
                .flatMapMany(connection -> connection.createStatement("SELECT 1").execute())
                .map(result -> result.map((row, rowMetadata) -> new IllegalArgumentException()))
                .then();
    }
}

Error log

Provided function caused exception: IllegalArgumentException

However, exception is just logged and not propagated.

Configuration

Environment

  • Client version: 0.6.5.
  • Language version: Java.
  • OS: Mac, Linux.

ClickHouse server

  • ClickHouse Server version: 24.3.8.13.
  • ClickHouse Server non-default settings, if any: N/A.
  • CREATE TABLE statements for tables involved: N/A.
  • Sample data for all these tables, use clickhouse-obfuscator if necessary: N/A.

Activity

  1. added
    connectivity
    on Jan 10, 2025
  2. github-actions commented on Jan 10, 2026

    @github-actions

    This issue has been automatically marked as stale because it has not had activity in the last year. It will be closed in 30 days if no further activity occurs. Please feel free to leave a comment if you believe the issue is still relevant. Thank you for your contributions!

  3. andrescrz commented on Jan 12, 2026

    @andrescrz
    Author

    Hi @chernser any update about the issue that I reported here? Thanks a lot.

  4. polyglotAI-bot commented on Nov 28, 2026

    @polyglotAI-bot
    Collaborator

    Recommendation: Keep open — fix needed
    A fix is needed in ClickHouseResult.map; no open PR changes its error handling.

    • Category: Bug
    • Classification: impact: Data integrity · area: API & diagnostics (R2DBC Result.map)
    • Status on main: Reproduced on main — a throw drops that row, a failing row.get drops all rows, and each result completes with no error; flatMap signals the error.
    • Breaking change: No.
    • Duplicates / related: Related: open PR [r2dbc] Fix response leaks on query cancellation #3354 changes ClickHouseResult for response leaks, not map.
    • Workaround: Use Result.flatMap and read Result.RowSegment.row(): the run shows that it signals the error.

    Analysis: Confirmed: ClickHouseResult.java:59-64 on main catches every Exception of the function, logs it, and does not call sink.error. So the row is dropped and the publisher completes normally. An exception of the driver's own Row.get (ClickHouseRow.java:45) inside the function is hidden the same way.

    Reproduction: complete program and output

    Changed from the issue's steps: the function throws the exception (the issue's example returns it); added a row.get case and a flatMap contrast.

    import io.r2dbc.spi.Connection;
    import io.r2dbc.spi.ConnectionFactories;
    import io.r2dbc.spi.ConnectionFactory;
    import io.r2dbc.spi.Result;
    import org.reactivestreams.Publisher;
    import reactor.core.publisher.Flux;
    import reactor.core.publisher.Mono;
    
    import java.util.List;
    import java.util.function.Function;
    
    public class Repro {
        static final String URL = System.getenv().getOrDefault("CLICKHOUSE_URL", "http://localhost:8123");
        static final String PASSWORD = System.getenv().getOrDefault("CLICKHOUSE_PASSWORD", "");
        // compress=0: avoids clickhouse-java#3107 (v1 compressed reads fail on server 26.9+)
        static final ConnectionFactory CF = ConnectionFactories.get("r2dbc:clickhouse:"
                + URL.replaceFirst("^https?:", "").replaceFirst("//", "//default:" + PASSWORD + "@")
                + "/default?compress=0");
        static final String SQL = "SELECT toInt32(number) AS n FROM numbers(3)";
    
        public static void main(String[] args) {
            run("map, the function throws for n = 1", result -> result.map((row, md) -> {
                Integer n = row.get("n", Integer.class);
                if (n == 1) {
                    throw new IllegalArgumentException("thrown for n = 1");
                }
                return n;
            }));
            run("map, row.get of a missing column", result -> result.map((row, md) -> row.get("missing", Integer.class)));
            run("flatMap, the function throws for n = 1", result -> result.flatMap(segment -> {
                if (!(segment instanceof Result.RowSegment)) {
                    return Mono.empty();
                }
                Integer n = ((Result.RowSegment) segment).row().get("n", Integer.class);
                if (n == 1) {
                    throw new IllegalArgumentException("thrown for n = 1");
                }
                return Mono.just(n);
            }));
        }
    
        static void run(String name, Function<Result, Publisher<?>> mapping) {
            try {
                List<?> rows = Flux.usingWhen(CF.create(),
                        conn -> Flux.from(conn.createStatement(SQL).execute()).flatMap(mapping),
                        Connection::close).collectList().block();
                System.out.println(name + ": completed with no error, rows = " + rows);
            } catch (Exception e) {
                System.out.println(name + ": error " + e.getClass().getName() + ": " + e.getMessage());
            }
        }
    }

    Output on main (8480ca001), ClickHouse 26.11.4.11:

    … ERROR ClickHouseResult - Provided function caused exception:
    java.lang.IllegalArgumentException: thrown for n = 1
    …
    map, the function throws for n = 1: completed with no error, rows = [0, 2]
    … ERROR ClickHouseResult - Provided function caused exception:
    java.util.NoSuchElementException: Unknown element with a name missing
    …
    map, row.get of a missing column: completed with no error, rows = []
    flatMap, the function throws for n = 1: error java.lang.IllegalArgumentException: thrown for n = 1
    

    Automated triage by Polyglot AI. A maintainer makes the final decision.

  5. added
    api-diagnostics
    on Nov 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    api-diagnosticsbugconnectivityr2dbc

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions