[
https://issues.apache.org/jira/browse/FLINK-38273?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18015596#comment-18015596
]
shml commented on FLINK-38273:
------------------------------
I may have identified the root cause and implemented a fix for this issue.
The problem is in the `EmbeddedGateway.create()` method in `SqlClient.java`.
When the user configures `rest.bind-port`, this configuration overrides the
embedded gateway's random port due to configuration
priority issues in the `defaultConfig.addAll()` operation.
I've added a line to explicitly set the `BIND_PORT` configuration to ensure the
embedded gateway uses the random port:
```java
if (defaultConfig.containsKey(RestOptions.BIND_PORT.key())) {
restConfig.set(SqlGatewayRestOptions.BIND_PORT,
String.valueOf(port.getPort()));
}
```
> SQL Client Embedded Mode Fails to Connect When rest.bind-port is Set
> --------------------------------------------------------------------
>
> Key: FLINK-38273
> URL: https://issues.apache.org/jira/browse/FLINK-38273
> Project: Flink
> Issue Type: Bug
> Components: Table SQL / Client
> Affects Versions: 1.19.1, 1.19.2, 1.19.3, 1.20.2
> Reporter: shml
> Priority: Major
> Labels: Configuration, embedded, sql-gateway
>
> h2. Description
> The Flink SQL Client in embedded mode fails to start in version 1.19 when
> {{rest.bind-port}} is configured, while it works fine in version 1.18. This
> appears to be a configuration system regression that breaks the embedded
> gateway functionality.
> h2. Steps to Reproduce
> # Configure {{rest.bind-port as 8080-8090}} in {{config.yaml}}
> # Start SQL Client in embedded mode: {{./bin/sql-client.sh}}
> # Client fails with connection refused error
> h2. Expected Behavior
> The SQL Client should start successfully and connect to the embedded gateway,
> ignoring the {{rest.bind-port}} configuration in embedded mode (as it did in
> 1.18).
> h2. Actual Behavior
> The SQL Client fails to start with:
> Exception in thread "main" org.apache.flink.table.client.SqlClientException:
> Failed to create the executor.
> at
> org.apache.flink.table.client.gateway.ExecutorImpl.<init>(ExecutorImpl.java:230)
> at
> org.apache.flink.table.client.gateway.ExecutorImpl.<init>(ExecutorImpl.java:126)
> at
> org.apache.flink.table.client.gateway.Executor.create(Executor.java:37)
> at org.apache.flink.table.client.SqlClient.start(SqlClient.java:110)
> at
> org.apache.flink.table.client.SqlClient.startClient(SqlClient.java:228)
> at org.apache.flink.table.client.SqlClient.main(SqlClient.java:179)
> Caused by: org.apache.flink.table.client.gateway.SqlExecutionException:
> Failed to get response.
> at
> org.apache.flink.table.client.gateway.ExecutorImpl.getResponse(ExecutorImpl.java:508)
> at
> org.apache.flink.table.client.gateway.ExecutorImpl.getResponse(ExecutorImpl.java:497)
> at
> org.apache.flink.table.client.gateway.ExecutorImpl.negotiateVersion(ExecutorImpl.java:536)
> at
> org.apache.flink.table.client.gateway.ExecutorImpl.<init>(ExecutorImpl.java:193)
> ... 5 more
> Caused by:
> org.apache.flink.shaded.netty4.io.netty.channel.AbstractChannel$AnnotatedConnectException:
> Connection refused: localhost/127.0.0.1:42735
> Caused by: java.net.ConnectException: Connection refused
> at sun.nio.ch.SocketChannelImpl.checkConnect(Native Method)
> at
> sun.nio.ch.SocketChannelImpl.finishConnect(SocketChannelImpl.java:715)
> at
> org.apache.flink.shaded.netty4.io.netty.channel.socket.nio.NioSocketChannel.doFinishConnect(NioSocketChannel.java:337)
> at
> org.apache.flink.shaded.netty4.io.netty.channel.nio.AbstractNioChannel$AbstractNioUnsafe.finishConnect(AbstractNioChannel.java:334)
> at
> org.apache.flink.shaded.netty4.io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:776)
> at
> org.apache.flink.shaded.netty4.io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:724)
> at
> org.apache.flink.shaded.netty4.io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:650)
> at
> org.apache.flink.shaded.netty4.io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:562)
> at
> org.apache.flink.shaded.netty4.io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:997)
> at
> org.apache.flink.shaded.netty4.io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74)
> at java.lang.Thread.run(Thread.java:750)
--
This message was sent by Atlassian Jira
(v8.20.10#820010)