makssent opened a new issue, #40240: URL: https://github.com/apache/shardingsphere/issues/40240
### Before reporting a bug - [x] I have searched open and closed [GitHub issues](https://github.com/apache/shardingsphere/issues). - [x] I have read the [ShardingSphere documentation](https://shardingsphere.apache.org/document/current/en/overview). ### ShardingSphere version master, commit [`01446d4fad4`](https://github.com/apache/shardingsphere/commit/01446d4fad48450e7fc3eb3b3631b25d6bf411df) ### ShardingSphere project ShardingSphere-Proxy ### Expected behavior The proxy should answer [`op_attach`](https://github.com/FirebirdSQL/firebird/blob/v5.0.4/src/remote/server/server.cpp#L5077-L5079) to a database that does not exist with the same error as the Firebird server. ### Actual behavior The proxy answers with another error code than the Firebird server. The same steps were executed directly on the Firebird server and through the proxy, with the database name shown as `[database]` in the messages: | Steps | Firebird server | Proxy | | --- | --- | --- | | Connect ([`op_attach`](https://github.com/FirebirdSQL/firebird/blob/v5.0.4/src/remote/server/server.cpp#L5077-L5079)) to a database that does not exist (through the proxy `firebird_db_nosuch`, directly a database file that does not exist) | Error [`isc_io_error`](https://github.com/FirebirdSQL/firebird/blob/v5.0.4/src/jrd/os/posix/unix.cpp#L687-L688) "I/O error during "open" operation for file "[database]"; Error while trying to open file; No such file or directory" | Error [`isc_unavailable`](https://github.com/FirebirdSQL/firebird/blob/v5.0.4/src/include/firebird/impl/msg/jrd.h#L56) "unavailable database; [database]" | So an application that checks the error code to tell a wrong database name from an unavailable database gets a different answer through the proxy. ### Reason analysis - [`FirebirdAuthenticationEngine#login`](https://github.com/apache/shardingsphere/blob/01446d4fad48450e7fc3eb3b3631b25d6bf411df/proxy/frontend/dialect/firebird/src/main/java/org/apache/shardingsphere/proxy/frontend/firebird/authentication/FirebirdAuthenticationEngine.java#L114-L117) throws [`UnknownDatabaseException`](https://github.com/apache/shardingsphere/blob/01446d4fad48450e7fc3eb3b3631b25d6bf411df/database/exception/core/src/main/java/org/apache/shardingsphere/database/exception/core/exception/syntax/database/UnknownDatabaseException.java#L29) when the database from [`op_attach`](https://github.com/FirebirdSQL/firebird/blob/v5.0.4/src/remote/server/server.cpp#L5077-L5079) is not in the proxy configuration. - [`FirebirdDialectExceptionMapper#convert`](https://github.com/apache/shardingsphere/blob/01446d4fad48450e7fc3eb3b3631b25d6bf411df/database/exception/dialect/firebird/src/main/java/org/apache/shardingsphere/database/exception/firebird/mapper/FirebirdDialectExceptionMapper.java#L55-L56) maps [`UnknownDatabaseException`](https://github.com/apache/shardingsphere/blob/01446d4fad48450e7fc3eb3b3631b25d6bf411df/database/exception/core/src/main/java/org/apache/shardingsphere/database/exception/core/exception/syntax/database/UnknownDatabaseException.java#L29) to [`FirebirdVendorError.UNAVAILABLE_DATABASE`](https://github.com/apache/shardingsphere/blob/01446d4fad48450e7fc3eb3b3631b25d6bf411df/database/exception/dialect/firebird/src/main/java/org/apache/shardingsphere/database/exception/firebird/vendor/FirebirdVendorError.java#L41), that is [`isc_unavailable`](https://github.com/FirebirdSQL/firebird/blob/v5.0.4/src/include/firebird/impl/msg/jrd.h#L56). The Firebird server answers with [`isc _io_error`](https://github.com/FirebirdSQL/firebird/blob/v5.0.4/src/jrd/os/posix/unix.cpp#L687-L688) and [`isc_io_open_err`](https://github.com/FirebirdSQL/firebird/blob/v5.0.4/src/jrd/os/posix/unix.cpp#L687-L688) when it cannot open the database file in [`PIO_open`](https://github.com/FirebirdSQL/firebird/blob/v5.0.4/src/jrd/os/posix/unix.cpp#L658-L689). ### Steps to reproduce #### Environment - Firebird server 5.0. - Client: Jaybird 6.0.7. #### Steps 1. Start ShardingSphere-Proxy with this configuration: ```yaml # global.yaml authority: users: - user: root@% password: root privilege: type: ALL_PERMITTED props: proxy-frontend-database-protocol-type: Firebird ``` ```yaml # database-firebird.yaml databaseName: firebird_db dataSources: ds_0: url: jdbc:firebirdsql://<host>/<database file> username: <user> password: <password> rules: - !SINGLE tables: - "*.*" ``` 2. Execute the steps from the table under "Actual behavior" through the proxy and directly on the Firebird server, and compare the results. "Example code" runs all of them. ### Example code All cases on Jaybird 6.0.7, one method per case. The comment above each method shows what it prints against the Firebird server and through the proxy. ```java import java.sql.Connection; import java.sql.DriverManager; import java.sql.SQLException; import java.util.Properties; public class UnknownDatabase { // The proxy; put the URL of the Firebird server here to compare static final String URL = "jdbc:firebirdsql://<proxy host>:<proxy port>/firebird_db"; static final String USER = "root"; static final String PASSWORD = "root"; public static void main(final String[] args) { unknownDatabase(); } // Firebird server: "I/O error during "open" operation for file "[database]"; Error while trying to open file; // No such file or directory [SQLState:08001, ISC error code:335544344]"; // proxy: "unavailable database; [database] [SQLState:08001, ISC error code:335544375]" static void unknownDatabase() { // The proxy has no logical database with this name, the Firebird server has no file with this name String url = URL + "_nosuch"; String database = url.substring(url.indexOf('/', "jdbc:firebirdsql://".length()) + 1); Properties properties = new Properties(); properties.setProperty("user", USER); properties.setProperty("password", PASSWORD); properties.setProperty("encoding", "UTF8"); properties.setProperty("wireCrypt", "DISABLED"); try (Connection ignored = DriverManager.getConnection(url, properties)) { System.out.println("connected"); } catch (final SQLException ex) { // The name differs between the proxy and the Firebird server, so it is printed as [database] System.out.println(ex.getMessage().replace(database, "[database]")); } } } ``` -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
