This is an automated email from the ASF dual-hosted git repository. github-merge-queue[bot] pushed a commit to branch gh-readonly-queue/dev/pr-13309-3f6dfe2fb73d14e71104f88aae130cd6e4ba74ea in repository https://gitbox.apache.org/repos/asf/seatunnel.git
commit ca1746c0093884754d4cf245b2041c893ef2ba8d Author: chovygo <[email protected]> AuthorDate: Sun Nov 22 12:50:39 2026 +0000 [Fix] [Connector-V2] Make request timeouts effective for Doris source FE requests (#13309) Co-authored-by: zhaowei <[email protected]> --- docs/en/connectors/source/Doris.md | 2 +- docs/zh/connectors/source/Doris.md | 2 +- .../connectors/doris/rest/RestService.java | 36 +++-- .../connectors/doris/rest/RestServiceTest.java | 158 +++++++++++++++++++++ .../split/DorisSourceSplitEnumeratorTest.java | 38 ++--- .../seatunnel/e2e/connector/doris/DorisIT.java | 69 +++++++++ .../resources/doris_source_fe_unreachable.conf | 43 ++++++ 7 files changed, 316 insertions(+), 32 deletions(-) diff --git a/docs/en/connectors/source/Doris.md b/docs/en/connectors/source/Doris.md index f06136fd3ac..bfe78635c55 100644 --- a/docs/en/connectors/source/Doris.md +++ b/docs/en/connectors/source/Doris.md @@ -73,7 +73,7 @@ Base configuration: | username | string | yes | - | User username | | password | string | yes | - | User password | | doris.request.retries | int | no | 3 | Number of retries to send requests to Doris FE. | -| doris.request.read.timeout.ms | int | no | 30000 | Socket read timeout for requests sent to Doris BE. | +| doris.request.read.timeout.ms | int | no | 30000 | Socket read timeout for requests sent to Doris FE or BE. | | doris.request.connect.timeout.ms | int | no | 30000 | Connection timeout for requests sent to Doris FE or BE. | | query-port | int | no | 9030 | Doris query port. | | doris.request.query.timeout.s | int | no | 3600 | Timeout period of Doris scan data, expressed in seconds. | diff --git a/docs/zh/connectors/source/Doris.md b/docs/zh/connectors/source/Doris.md index 19eb315c705..5e2a9584169 100644 --- a/docs/zh/connectors/source/Doris.md +++ b/docs/zh/connectors/source/Doris.md @@ -73,7 +73,7 @@ import ChangeLog from '../changelog/connector-doris.md'; | username | string | yes | - | 用户名 | | password | string | yes | - | 密码 | | doris.request.retries | int | no | 3 | 请求Doris FE的重试次数 | -| doris.request.read.timeout.ms | int | no | 30000 | 请求 Doris BE 的 socket 读取超时时间。 | +| doris.request.read.timeout.ms | int | no | 30000 | 请求 Doris FE 或 BE 的 socket 读取超时时间。 | | doris.request.connect.timeout.ms | int | no | 30000 | 请求 Doris FE 或 BE 的连接超时时间。 | | query-port | int | no | 9030 | Doris 查询端口。 | | doris.request.query.timeout.s | int | no | 3600 | Doris扫描数据的超时时间,单位秒 | diff --git a/seatunnel-connectors-v2/connector-doris/src/main/java/org/apache/seatunnel/connectors/doris/rest/RestService.java b/seatunnel-connectors-v2/connector-doris/src/main/java/org/apache/seatunnel/connectors/doris/rest/RestService.java index caa1ce3ec2a..edc5d608a74 100644 --- a/seatunnel-connectors-v2/connector-doris/src/main/java/org/apache/seatunnel/connectors/doris/rest/RestService.java +++ b/seatunnel-connectors-v2/connector-doris/src/main/java/org/apache/seatunnel/connectors/doris/rest/RestService.java @@ -35,7 +35,6 @@ import org.apache.seatunnel.connectors.doris.util.ErrorMessages; import org.apache.commons.io.IOUtils; import org.apache.http.HttpStatus; -import org.apache.http.client.config.RequestConfig; import org.apache.http.client.methods.HttpGet; import org.apache.http.client.methods.HttpPost; import org.apache.http.client.methods.HttpRequestBase; @@ -71,8 +70,8 @@ public class RestService implements Serializable { private static final String QUERY_PLAN = "_query_plan"; private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper(); - private static String send( - DorisSourceConfig dorisSourceConfig, HttpRequestBase request, Logger logger) + @VisibleForTesting + static String send(DorisSourceConfig dorisSourceConfig, HttpRequestBase request, Logger logger) throws DorisConnectorException { int connectTimeout = dorisSourceConfig.getRequestConnectTimeoutMs(); int socketTimeout = dorisSourceConfig.getRequestReadTimeoutMs(); @@ -83,13 +82,6 @@ public class RestService implements Serializable { socketTimeout, retries); - RequestConfig requestConfig = - RequestConfig.custom() - .setConnectTimeout(connectTimeout) - .setSocketTimeout(socketTimeout) - .build(); - - request.setConfig(requestConfig); logger.info( "Send request to Doris FE '{}' with user '{}'.", request.getURI(), @@ -107,6 +99,8 @@ public class RestService implements Serializable { request.getURI().toString(), dorisSourceConfig.getUsername(), dorisSourceConfig.getPassword(), + connectTimeout, + socketTimeout, logger); } else { response = @@ -114,6 +108,8 @@ public class RestService implements Serializable { request, dorisSourceConfig.getUsername(), dorisSourceConfig.getPassword(), + connectTimeout, + socketTimeout, logger); } if (StringUtils.isEmpty(response)) { @@ -150,9 +146,17 @@ public class RestService implements Serializable { } private static String getConnectionPost( - HttpRequestBase request, String user, String passwd, Logger logger) throws IOException { + HttpRequestBase request, + String user, + String passwd, + int connectTimeout, + int socketTimeout, + Logger logger) + throws IOException { URL url = new URL(request.getURI().toString()); HttpURLConnection conn = (HttpURLConnection) url.openConnection(); + conn.setConnectTimeout(connectTimeout); + conn.setReadTimeout(socketTimeout); conn.setInstanceFollowRedirects(false); conn.setRequestMethod(request.getMethod()); String authEncoding = @@ -175,10 +179,18 @@ public class RestService implements Serializable { } private static String getConnectionGet( - String request, String user, String passwd, Logger logger) throws IOException { + String request, + String user, + String passwd, + int connectTimeout, + int socketTimeout, + Logger logger) + throws IOException { URL realUrl = new URL(request); // open connection HttpURLConnection connection = (HttpURLConnection) realUrl.openConnection(); + connection.setConnectTimeout(connectTimeout); + connection.setReadTimeout(socketTimeout); String authEncoding = Base64.getEncoder() .encodeToString( diff --git a/seatunnel-connectors-v2/connector-doris/src/test/java/org/apache/seatunnel/connectors/doris/rest/RestServiceTest.java b/seatunnel-connectors-v2/connector-doris/src/test/java/org/apache/seatunnel/connectors/doris/rest/RestServiceTest.java new file mode 100644 index 00000000000..9a6bf770b82 --- /dev/null +++ b/seatunnel-connectors-v2/connector-doris/src/test/java/org/apache/seatunnel/connectors/doris/rest/RestServiceTest.java @@ -0,0 +1,158 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.seatunnel.connectors.doris.rest; + +import org.apache.seatunnel.api.configuration.ReadonlyConfig; +import org.apache.seatunnel.connectors.doris.config.DorisSourceConfig; +import org.apache.seatunnel.connectors.doris.exception.DorisConnectorException; + +import org.apache.http.client.methods.HttpGet; +import org.apache.http.client.methods.HttpPost; +import org.apache.http.client.methods.HttpRequestBase; +import org.apache.http.entity.StringEntity; + +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.Timeout; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.sun.net.httpserver.HttpServer; + +import java.io.IOException; +import java.io.OutputStream; +import java.net.InetSocketAddress; +import java.net.SocketTimeoutException; +import java.nio.charset.StandardCharsets; +import java.util.HashMap; +import java.util.Map; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.TimeUnit; + +public class RestServiceTest { + + private static final Logger LOG = LoggerFactory.getLogger(RestServiceTest.class); + + private static final String QUERY_PLAN_PATH = "/api/test_db/test_table/_query_plan"; + private static final int READ_TIMEOUT_MS = 1000; + private static final int SERVER_DELAY_MS = 10 * 1000; + + private HttpServer server; + private ExecutorService serverExecutor; + private DorisSourceConfig config; + + /** + * Starts a local FE stub that delays every response far beyond the configured read timeout, so + * a request without an effective read timeout blocks for the full delay, while one with an + * effective read timeout fails fast with a SocketTimeoutException. + */ + @BeforeEach + void setUp() throws IOException { + server = HttpServer.create(new InetSocketAddress("127.0.0.1", 0), 0); + server.createContext( + QUERY_PLAN_PATH, + exchange -> { + try { + Thread.sleep(SERVER_DELAY_MS); + byte[] body = "{}".getBytes(StandardCharsets.UTF_8); + exchange.sendResponseHeaders(200, body.length); + try (OutputStream out = exchange.getResponseBody()) { + out.write(body); + } + } catch (InterruptedException e) { + Thread.currentThread().interrupt(); + } catch (IOException ignored) { + // the client may time out and disconnect before the response is sent + } + }); + serverExecutor = + Executors.newCachedThreadPool( + runnable -> { + Thread thread = new Thread(runnable); + thread.setDaemon(true); + return thread; + }); + server.setExecutor(serverExecutor); + server.start(); + + Map<String, Object> options = new HashMap<>(); + options.put("fenodes", "127.0.0.1:" + server.getAddress().getPort()); + options.put("username", "root"); + options.put("password", ""); + options.put("database", "test_db"); + options.put("table", "test_table"); + options.put("doris.request.connect.timeout.ms", READ_TIMEOUT_MS); + options.put("doris.request.read.timeout.ms", READ_TIMEOUT_MS); + options.put("doris.request.retries", 1); + config = DorisSourceConfig.of(ReadonlyConfig.fromMap(options)); + } + + @AfterEach + void tearDown() throws InterruptedException { + if (server != null) { + server.stop(0); + } + if (serverExecutor != null) { + serverExecutor.shutdown(); + if (!serverExecutor.awaitTermination(5, TimeUnit.SECONDS)) { + serverExecutor.shutdownNow(); + } + } + } + + @Test + @Timeout(30) + void testGetRequestHonorsReadTimeout() { + HttpGet request = new HttpGet(queryPlanUrl()); + assertReadTimeoutFailsFast(request); + } + + @Test + @Timeout(30) + void testPostRequestHonorsReadTimeout() throws Exception { + HttpPost request = new HttpPost(queryPlanUrl()); + request.setEntity(new StringEntity("{\"sql\":\"select 1\"}", StandardCharsets.UTF_8)); + assertReadTimeoutFailsFast(request); + } + + private String queryPlanUrl() { + return "http://127.0.0.1:" + server.getAddress().getPort() + QUERY_PLAN_PATH; + } + + private void assertReadTimeoutFailsFast(HttpRequestBase request) { + long start = System.nanoTime(); + DorisConnectorException exception = + Assertions.assertThrows( + DorisConnectorException.class, + () -> RestService.send(config, request, LOG)); + long elapsedMs = (System.nanoTime() - start) / 1_000_000; + Assertions.assertTrue( + exception.getCause() instanceof SocketTimeoutException, + "expected a SocketTimeoutException cause but got: " + exception.getCause()); + // The budget only proves the request did not wait out the server's delayed response, so a + // paused or loaded CI worker cannot fail otherwise correct behavior. + Assertions.assertTrue( + elapsedMs < SERVER_DELAY_MS, + "request should fail before the server's delayed response but took " + + elapsedMs + + "ms"); + } +} diff --git a/seatunnel-connectors-v2/connector-doris/src/test/java/org/apache/seatunnel/connectors/doris/split/DorisSourceSplitEnumeratorTest.java b/seatunnel-connectors-v2/connector-doris/src/test/java/org/apache/seatunnel/connectors/doris/split/DorisSourceSplitEnumeratorTest.java index 39478dd0090..6eb1100ffa4 100644 --- a/seatunnel-connectors-v2/connector-doris/src/test/java/org/apache/seatunnel/connectors/doris/split/DorisSourceSplitEnumeratorTest.java +++ b/seatunnel-connectors-v2/connector-doris/src/test/java/org/apache/seatunnel/connectors/doris/split/DorisSourceSplitEnumeratorTest.java @@ -87,31 +87,33 @@ public class DorisSourceSplitEnumeratorTest { DorisSourceSplitEnumerator dorisSourceSplitEnumerator = new DorisSourceSplitEnumerator(context, dorisSourceConfig, dorisSourceTableMap); - MockedStatic<RestService> restServiceMockedStatic = Mockito.mockStatic(RestService.class); + try (MockedStatic<RestService> restServiceMockedStatic = + Mockito.mockStatic(RestService.class)) { + restServiceMockedStatic + .when(() -> RestService.findPartitions(any(), any(), any())) + .thenReturn(buildPartitionDefinitions()); - restServiceMockedStatic - .when(() -> RestService.findPartitions(any(), any(), any())) - .thenReturn(buildPartitionDefinitions()); + dorisSourceSplitEnumerator.run(); - dorisSourceSplitEnumerator.run(); + ArgumentCaptor<Integer> subtaskId = ArgumentCaptor.forClass(Integer.class); + ArgumentCaptor<List> split = ArgumentCaptor.forClass(List.class); - ArgumentCaptor<Integer> subtaskId = ArgumentCaptor.forClass(Integer.class); - ArgumentCaptor<List> split = ArgumentCaptor.forClass(List.class); + Mockito.verify(context, Mockito.times(PARALLELISM)) + .assignSplit(subtaskId.capture(), split.capture()); - Mockito.verify(context, Mockito.times(PARALLELISM)) - .assignSplit(subtaskId.capture(), split.capture()); + List<Integer> subTaskAllValues = subtaskId.getAllValues(); + List<List> splitAllValues = split.getAllValues(); - List<Integer> subTaskAllValues = subtaskId.getAllValues(); - List<List> splitAllValues = split.getAllValues(); + for (int i = 0; i < PARALLELISM; i++) { + Assertions.assertEquals(i, subTaskAllValues.get(i)); + Assertions.assertEquals( + allocateFiles(i, PARALLELISM, PARTITION_NUMS), + splitAllValues.get(i).size()); + } - for (int i = 0; i < PARALLELISM; i++) { - Assertions.assertEquals(i, subTaskAllValues.get(i)); - Assertions.assertEquals( - allocateFiles(i, PARALLELISM, PARTITION_NUMS), splitAllValues.get(i).size()); + // check no duplicate file assigned + Assertions.assertEquals(0, dorisSourceSplitEnumerator.currentUnassignedSplitSize()); } - - // check no duplicate file assigned - Assertions.assertEquals(0, dorisSourceSplitEnumerator.currentUnassignedSplitSize()); } private List<PartitionDefinition> buildPartitionDefinitions() { diff --git a/seatunnel-e2e/seatunnel-connector-v2-e2e/connector-doris-e2e/src/test/java/org/apache/seatunnel/e2e/connector/doris/DorisIT.java b/seatunnel-e2e/seatunnel-connector-v2-e2e/connector-doris-e2e/src/test/java/org/apache/seatunnel/e2e/connector/doris/DorisIT.java index 84226f0343f..f789186f213 100644 --- a/seatunnel-e2e/seatunnel-connector-v2-e2e/connector-doris-e2e/src/test/java/org/apache/seatunnel/e2e/connector/doris/DorisIT.java +++ b/seatunnel-e2e/seatunnel-connector-v2-e2e/connector-doris-e2e/src/test/java/org/apache/seatunnel/e2e/connector/doris/DorisIT.java @@ -20,9 +20,12 @@ package org.apache.seatunnel.e2e.connector.doris; import org.apache.seatunnel.api.table.type.SeaTunnelRow; import org.apache.seatunnel.common.utils.ExceptionUtils; import org.apache.seatunnel.common.utils.JsonUtils; +import org.apache.seatunnel.connectors.doris.exception.DorisConnectorErrorCode; import org.apache.seatunnel.connectors.doris.util.DorisCatalogUtil; import org.apache.seatunnel.e2e.common.container.ContainerExtendedFactory; +import org.apache.seatunnel.e2e.common.container.EngineType; import org.apache.seatunnel.e2e.common.container.TestContainer; +import org.apache.seatunnel.e2e.common.junit.DisabledOnContainer; import org.apache.seatunnel.e2e.common.junit.TestContainerExtension; import org.apache.seatunnel.e2e.common.util.DependencyJar; @@ -40,12 +43,14 @@ import java.math.BigDecimal; import java.net.HttpURLConnection; import java.net.URL; import java.net.URLClassLoader; +import java.nio.charset.StandardCharsets; import java.sql.Connection; import java.sql.Driver; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; +import java.time.Duration; import java.time.LocalDateTime; import java.time.OffsetDateTime; import java.time.ZoneId; @@ -262,6 +267,70 @@ public class DorisIT extends AbstractDorisIT { checkSinkData(); } + /** + * A FE port that silently drops SYN packets must make source startup/planning fail within the + * configured connect timeout instead of hanging the job. The catalog JDBC connection still uses + * the reachable query port on the same host, so only the RestService request path is + * black-holed: without the fix the job waits for the kernel SYN retries, with it the planning + * failure propagates as REST_SERVICE_FAILED. + */ + @TestTemplate + @DisabledOnContainer( + value = {}, + type = {EngineType.SPARK, EngineType.FLINK}, + disabledReason = "flink/spark failed reason not same") + public void testSourceFailsFastWhenFeUnreachable(TestContainer container) throws Exception { + initializeJdbcTable(); + String dorisPid = String.valueOf(this.container.getContainerInfo().getState().getPid()); + // The Doris image ships no iptables binary, so run the host's iptables inside the + // container's network namespace: every packet the container receives traverses INPUT, + // which turns the otherwise refused port 9999 into a silent SYN black hole. + hostIptables(dorisPid, "-A"); + try { + Container.ExecResult execResult = + Assertions.assertTimeoutPreemptively( + Duration.ofSeconds(60), + () -> container.executeJob("/doris_source_fe_unreachable.conf")); + Assertions.assertNotEquals(0, execResult.getExitCode()); + Assertions.assertTrue( + execResult + .getStderr() + .contains(DorisConnectorErrorCode.REST_SERVICE_FAILED.getCode()), + "expected REST_SERVICE_FAILED in the job output:\n" + execResult.getStderr()); + Assertions.assertTrue( + execResult.getStderr().contains("connect timed out"), + "expected the configured connect timeout to fire:\n" + execResult.getStderr()); + } finally { + hostIptables(dorisPid, "-D"); + } + } + + private void hostIptables(String dorisPid, String action) + throws IOException, InterruptedException { + Process process = + new ProcessBuilder( + "sudo", + "nsenter", + "-t", + dorisPid, + "-n", + "iptables", + action, + "INPUT", + "-p", + "tcp", + "--dport", + "9999", + "-j", + "DROP") + .redirectErrorStream(true) + .start(); + String output = new String(process.getInputStream().readAllBytes(), StandardCharsets.UTF_8); + int exitCode = process.waitFor(); + Assertions.assertEquals( + 0, exitCode, "failed to update the container INPUT chain: " + output); + } + @TestTemplate public void testTimestampTzZoneWarning(TestContainer container) throws IOException, InterruptedException { diff --git a/seatunnel-e2e/seatunnel-connector-v2-e2e/connector-doris-e2e/src/test/resources/doris_source_fe_unreachable.conf b/seatunnel-e2e/seatunnel-connector-v2-e2e/connector-doris-e2e/src/test/resources/doris_source_fe_unreachable.conf new file mode 100644 index 00000000000..87847518e49 --- /dev/null +++ b/seatunnel-e2e/seatunnel-connector-v2-e2e/connector-doris-e2e/src/test/resources/doris_source_fe_unreachable.conf @@ -0,0 +1,43 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +env{ + parallelism = 1 + job.mode = "BATCH" + job.retry.times = 0 +} + +# The catalog JDBC connection still reaches the real Doris through the query port (9030), while +# the FE HTTP port 9999 is black-holed by the test via an iptables DROP rule, so only the +# RestService request path is exercised: the job must fail with the configured connect timeout +# instead of hanging in partition discovery. +source{ + Doris { + fenodes = "doris_e2e:9999" + username = root + password = "" + database = "e2e_source" + table = "doris_e2e_unique_table" + doris.request.connect.timeout.ms = 3000 + doris.request.read.timeout.ms = 3000 + doris.request.retries = 1 + } +} + +sink{ + Console {} +}
