Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Failure to connect to different port with FBWrappingDataSource [JDBC333] #379

Closed
firebird-automations opened this issue Dec 13, 2013 · 17 comments

Comments

@firebird-automations
Copy link

Submitted by: @pavel-zotov

Attachments:
attach_1_jaybird_datasource_connect_to_remote_database.zip
jdbc_connect_-_errors_differs_for_port_3252_vs_3050.zip
attach_2_jaybird_datasource_connect_to_remote_database.zip

Originally reported by Pavel Zotov on JDBC306:

Mark,

this problem also present in JayBird 2.2.4 if we try to connect to remote database.

Scenario:

-- first test that connection OK via isql:
isql 192.168.0.201/3252:employee
Database: 192.168.0.201/3252:employee
SQL> show version;
ISQL Version: WI-V2.5.3.26722 Firebird 2.5
Server version:
Firebird/x86/Windows NT (access method), version "WI-V2.5.3.26682 Firebird 2.5"
Firebird/x86/Windows NT (remote server), version "WI-V2.5.3.26682 Firebird 2.5/tcp (CSMIRROR)/P12"
Firebird/x86/Windows NT (remote interface), version "WI-V2.5.3.26722 Firebird 2.5/tcp (csprog)/P12"
on disk structure version 11.2

-- then try to connect and get some data using FBWrappingDataSource object
-- result: OK
-- (source code and output see in attach-1)

-- then try to connect via DriverManager:

>java -cp .;jaybird-full-2.2.4.jar DriverExample

Firebird JCA-JDBC driver version 2.0 registered with driver manager.
org.firebirdsql.jdbc.FBSQLException: GDS Exception. 335544721. Unable to complete network request to host "192.168.0.201".
at org.firebirdsql.jdbc.FBDataSource.getConnection(FBDataSource.java:123)
at org.firebirdsql.jdbc.AbstractDriver.connect(AbstractDriver.java:126)
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at DriverExample.main(DriverExample.java:167)
Caused by: org.firebirdsql.gds.GDSException: Unable to complete network request to host "192.168.0.201".
at org.firebirdsql.gds.impl.wire.AbstractJavaGDSImpl.connect(AbstractJavaGDSImpl.java:1875)
at org.firebirdsql.gds.impl.wire.AbstractJavaGDSImpl.internalAttachDatabase(AbstractJavaGDSImpl.java:431)
at org.firebirdsql.gds.impl.wire.AbstractJavaGDSImpl.iscAttachDatabase(AbstractJavaGDSImpl.java:411)
at org.firebirdsql.jca.FBManagedConnection.<init>(FBManagedConnection.java:105)
at org.firebirdsql.jca.FBManagedConnectionFactory.createManagedConnection(FBManagedConnectionFactory.java:490)
at org.firebirdsql.jca.FBStandAloneConnectionManager.allocateConnection(FBStandAloneConnectionManager.java:69)
at org.firebirdsql.jdbc.FBDataSource.getConnection(FBDataSource.java:120)
... 4 more
Caused by: java.net.ConnectException: Connection refused: connect
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(Unknown Source)
at java.net.PlainSocketImpl.connectToAddress(Unknown Source)
at java.net.PlainSocketImpl.connect(Unknown Source)
at java.net.SocksSocketImpl.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at org.firebirdsql.gds.impl.wire.AbstractJavaGDSImpl.openSocket(AbstractJavaGDSImpl.java:1969)
at org.firebirdsql.gds.impl.wire.AbstractJavaGDSImpl.connect(AbstractJavaGDSImpl.java:1852)
... 10 more
Unable to establish a connection through the driver manager.
GDS Exception. 335544721. Unable to complete network request to host "192.168.0.201".
Error Code: 335544721
SQL State: HY000
Closing database resources and rolling back any changes we made to the database.

file DriverExample.java see in attach-2

[ Permalink | Edit | Delete | « Hide ]
Mark Rotteveel added a comment - 12/Dec/13 10:59 PM - edited
Hi Pavel, that is not the same error as this issue is about. Your exception is a refused connection on the socket level, either because you specified the wrong port, the port isn't bound to the specified IP address or the port is shielded by a firewall.

The exception this issue is about is a weird problem where an existing, established connection suddenly breaks. The error message is the same, except that it doesn't include the hostname.

PS FBWrappingDataSource should be considered deprecated and will be removed in Jaybird 3.0 (the whole org.firebirdsql.pool package will be removed).

[ Permalink | Edit | Delete | « Hide ]
Pavel Zotov added a comment - 13/Dec/13 05:19 AM
> Your exception is a refused connection on the socket level, either because you specified the wrong port,
> the port isn't bound to the specified IP address or the port is shielded by a firewall.

Mark,
port is the same (3252). I've copied URL from isql connection argument that was issued before:

public final class DataSourceExample
{
private final static String DB_URL = "192.168.0.201/3252:employee";
private final static String DEFAULT_USER = "sysdba";
private final static String DEFAULT_PASS = "masterkey";

. . .

compare with:

public class DriverExample {
private static final String URL_DEFAULT = "jdbc:firebirdsql://192.168.0.201/3252:employee";
private static final String USER_DEFAULT = "sysdba";
private static final String PASSWORD_DEFAULT = "masterkey";
. . .

No firewall on that machine.
And I can`t understand what you mean by this: "port isn't bound to the specified IP" - do you mean to analyze result of netstat -a | findstr /c:3252
- ?
Result of netstat -an on server host (192.168.0.201/3252) when connect from isql was established:
netstat -an 3 | findstr /c:3252
TCP 0.0.0.0:3252 0.0.0.0:0 LISTENING
TCP 192.168.0.201:3252 192.168.43.96:4973 ESTABLISHED
TCP 0.0.0.0:3252 0.0.0.0:0 LISTENING
TCP 192.168.0.201:3252 192.168.43.96:4973 ESTABLISHED
TCP 0.0.0.0:3252 0.0.0.0:0 LISTENING
TCP 192.168.0.201:3252 192.168.43.96:4973 ESTABLISHED
TCP 0.0.0.0:3252 0.0.0.0:0 LISTENING
TCP 192.168.0.201:3252 192.168.43.96:4973 ESTABLISHED

================

> PS FBWrappingDataSource should be considered deprecated and will be removed in Jaybird 3.0

Sounds very unexpectedly.
So what about this ( $JayBird_HOME/examples/DataSourceExample.java ):

// The DataSource facility provides an alternative to the JDBC DriverManager,
// essentially duplicating all of the driver managerТs useful functionality.
// Although, both mechanisms may be used by the same application if desired,
// JavaSoft encourages developers to regard the DriverManager as a legacy
// feature of the JDBC API.
// Applications should use the DataSource API whenever possible.
// A JDBC implementation that is accessed via the DataSource API is not
// automatically registered with the DriverManager.
// The DriverManager, Driver, and DriverPropertyInfo interfaces
// may be deprecated in the future.

- ??

@firebird-automations
Copy link
Author

Modified by: @mrotteveel

reporter: Mark Rotteveel [ avalanche1979 ] => Pavel Zotov [ tabloid ]

@firebird-automations
Copy link
Author

Modified by: @mrotteveel

Attachment: attach_1_jaybird_datasource_connect_to_remote_database.zip [ 12400 ]

Attachment: attach_2_jaybird_datasource_connect_to_remote_database.zip [ 12401 ]

@firebird-automations
Copy link
Author

Commented by: @mrotteveel

It could be a bug that it tries to connect with the default port. I haven't had time to check yet.

Have you tried what happens when 1) you have a Firebird running on the default port and 2) you connect with the URL that contains the non-default port: does it connect to the default port?

Re deprecation of org.firebirdsql.pool.*:
This was announced together with the beta of Jaybird 2.2 in April of 2012. See the release notes of 2.2 http://www.firebirdsql.org/file/documentation/drivers_documentation/java/2.2.4/release_notes.html#__RefHeading__2753_1560579136 (and the section below that: "Removal of deprecated classes, packages and (interface) methods").

Re the comments in the example class (which really needs a re-write BTW, see JDBC215).:
This comment is not related to the deprecation of org.firebirdsql.pool.*. The classes in that package simply contain bugs that are hard to solve without a full re-implementation, and as there are good third-party connection pool implementations it makes no sense for us to spend time on trying to remake a connection pool that is mediocre at best.
Jaybird will still contain a normal DataSource implementation (and a XADataSource and ConnectionPoolDataSource implementation, just no connection pool).

The comment in the example class refers to when JDBC 2.0 standard extension was introduced (1998), Sun expected to deprecated DriverManager in future JDBC revisions. The JDBC 2 Standard Extension API spec says: "we encourage developers to regard the DriverManager as a legacy feature of the JDBC API. Applications should use the DataSource API whenever possible.". This deprecation never happened and current JDBC specification no longer says that DriverManager should be considered a legacy API.

@firebird-automations
Copy link
Author

Commented by: @pavel-zotov

> Have you tried what happens when
> 1) you have a Firebird running on the default port and

Yes, I've tried it just now, first connecting to remote machine (with address 192.168.0.201) and then moved JRE + class on that host and tried there to connect via specifying LOCALHOST instead of IP.

RESULT: the error code differs when port = 3050 was specified.
This error is:
------------
Unable to establish a connection through the driver manager.
GDS Exception. 335544375. unavailable database
Error Code: 335544375
SQL State: HY000
------------
Of course, I've checked in all cases that connection to database can be established via ISQL with specifying the same URL (only prefix "jdbc:firebirdsql://" was cuted off).

Please see new attach: class source + logs of calls for port 3050 vs 3252.

> 2) you connect with the URL that contains the non-default port: does it connect to the default port?

1. I did the following: set port to default 3050, restart FB

2. Check that connection will be OK if specify this port:
C:\1Install\FIREBIRD_2_5\bin\isql localhost/3050:employee
Database: localhost/3050:employee
SQL> show version;
ISQL Version: WI-V2.5.3.26682 Firebird 2.5
Server version:
Firebird/x86/Windows NT (access method), version "WI-V2.5.3.26682 Firebird 2.5"
Firebird/x86/Windows NT (remote server), version "WI-V2.5.3.26682 Firebird 2.5/tcp (CSMIRROR)/P12"
Firebird/x86/Windows NT (remote interface), version "WI-V2.5.3.26682 Firebird 2.5/tcp (CSMIRROR)/P12"
on disk structure version 11.2
SQL> quit;

3. Check the error code when in intentionally set port to wrong value (choosed 3210):

C:\1Install\FIREBIRD_2_5\bin\isql localhost/3210:employee
Statement failed, SQLSTATE = 08006
Unable to complete network request to host "localhost".
-Failed to establish a connection.
Use CONNECT or CREATE DATABASE to specify a database

4. Check what java class says in case when trying to connect via this 'wrong' port = 3210:

java -cp . DriverExample jdbc:firebirdsql://localhost/3210:employee >localhost_3210.log 2>localhost_3210.err

Content of localhost_3210.log:
----
Firebird JCA-JDBC driver version 2.0 registered with driver manager.

trying to connect to databaseURL=>jdbc:firebirdsql://localhost/3210:employee<
user=>sysdba<, password=>masterke<

Unable to establish a connection through the driver manager.
GDS Exception. 335544375. unavailable database
Error Code: 335544375
SQL State: HY000
Closing database resources and rolling back any changes we made to the database.
----

Content of localhost_3210.err:
----
org.firebirdsql.jdbc.FBSQLException: GDS Exception. 335544375. unavailable database
at org.firebirdsql.jdbc.FBDataSource.getConnection(FBDataSource.java:123)
at org.firebirdsql.jdbc.AbstractDriver.connect(AbstractDriver.java:126)
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at DriverExample.main(DriverExample.java:172)
Caused by: org.firebirdsql.gds.GDSException: unavailable database
at org.firebirdsql.gds.impl.wire.AbstractJavaGDSImpl.readStatusVector(AbstractJavaGDSImpl.java:2092)
at org.firebirdsql.gds.impl.wire.AbstractJavaGDSImpl.receiveResponse(AbstractJavaGDSImpl.java:2042)
at org.firebirdsql.gds.impl.wire.AbstractJavaGDSImpl.internalAttachDatabase(AbstractJavaGDSImpl.java:457)
at org.firebirdsql.gds.impl.wire.AbstractJavaGDSImpl.iscAttachDatabase(AbstractJavaGDSImpl.java:411)
at org.firebirdsql.jca.FBManagedConnection.<init>(FBManagedConnection.java:105)
at org.firebirdsql.jca.FBManagedConnectionFactory.createManagedConnection(FBManagedConnectionFactory.java:490)
at org.firebirdsql.jca.FBStandAloneConnectionManager.allocateConnection(FBStandAloneConnectionManager.java:69)
at org.firebirdsql.jdbc.FBDataSource.getConnection(FBDataSource.java:120)
... 4 more
----

So, there is two conclusions.

#⁠#⁠#⁠ 1 #⁠#⁠#⁠

We got the SAME error = 335544375 in both cases:
1.1) trying to connect using port that does not specified on firebird.conf (i.e. FB service does not listening on that port)
and
1.2) trying to connect using DEFAULT port (3050) and firebird service DOES listen this port.

There is BIG difference in behaviour of ISQL and java class when connect using 'wrong port': ISQL attempts lead to appering in firebird.log two messages:
----
CSMIRROR (Client) Sat Dec 14 09:43:21 2013
INET/inet_error: connect errno = 10061

CSMIRROR (Client) Sat Dec 14 09:43:24 2013
INET/inet_error: connect errno = 10061
----
Attempts of java class does NOT lead to any messages in firebird.log. Furthermore, when I specify wrong port, I can see some delay: ISQL really TRIES to connect, it SEARCHES something. In contrast with this, java class outputs error immediatelly, without any delay.

#⁠#⁠#⁠ 2 #⁠#⁠#⁠

We got error 335544721 (Unable to complete network request to host ". . .") whe trying to connect via JDBC DriverManager using CORRECT, but non-default, port = 3252.

And in this case there *IS* some delay when jdbc tries to connect. But there are NO any new messages in firebird.log.

HTH.

@firebird-automations
Copy link
Author

Commented by: @pavel-zotov

file jdbc_connect_-_errors_differs_for_port_3252_vs_3050.zip contains logs of stdout and sterrr in case of connecting to default and non-default ports. THEY DIFFERS!

@firebird-automations
Copy link
Author

Modified by: @pavel-zotov

Attachment: jdbc_connect_-_errors_differs_for_port_3252_vs_3050.zip [ 12402 ]

@firebird-automations
Copy link
Author

Commented by: @mrotteveel

I hadn't noticed it before, but the jdbc:firebirdsql://localhost/3210:employee you use with DriverManager is not a valid JDBC url (see http://www.firebirdsql.org/file/documentation/drivers_documentation/java/faq.html#pure-java-default ).
It is either:
* jdbc:firebirdsql:localhost/3210:employee
* jdbc:firebirdsql://localhost:3210/employee

The datasource url should be fine, but I was wondering if you have an alias for employee on localhost and not on 192.168.0.201?

Re #⁠#⁠#⁠ 1 #⁠#⁠#⁠:
Jaybird (when using the wire protocol implementation; the default) does not log the firebird.log, while fbclient.dll does. So it is expected that no *client* messages appear in the log for Jaybird. Error 10061 is connection refused, see http://msdn.microsoft.com/en-us/library/windows/desktop/ms740668%28v=vs.85%29.aspx

@firebird-automations
Copy link
Author

Commented by: @pavel-zotov

It seems that the problem was in two slahes in database URL, between "firebirdsql:" and ip-address (or hostname).

Compare:

java -cp .;jaybird-full-2.2.4.jar DriverExample jdbc:firebirdsql://192.168.0.201/3252:employee

Output:

Firebird JCA-JDBC driver version 2.0 registered with driver manager.

trying to connect to databaseURL=>jdbc:firebirdsql://192.168.0.201/3252:employee<
user=>sysdba<, password=>masterke<

org.firebirdsql.jdbc.FBSQLException: GDS Exception. 335544721. Unable to complete network request to host "192.168.0.201".
at org.firebirdsql.jdbc.FBDataSource.getConnection(FBDataSource.java:123)
at org.firebirdsql.jdbc.AbstractDriver.connect(AbstractDriver.java:126)
at java.sql.DriverManager.getConnection(Unknown Source)
. . .

#⁠#⁠#⁠ vs #⁠#⁠#⁠

java -cp .;jaybird-full-2.2.4.jar DriverExample jdbc:firebirdsql:192.168.0.201/3252:employee

Output:

Firebird JCA-JDBC driver version 2.0 registered with driver manager.

trying to connect to databaseURL=>jdbc:firebirdsql:192.168.0.201/3252:employee<
user=>sysdba<, password=>masterke<

Connection established.
Auto-commit is disabled.
Transactions are supported.
. . .

PS. I see in official JDBC doc and can`t find yet are these two slashes mandatory in database URL or not.

@firebird-automations
Copy link
Author

Commented by: @mrotteveel

See my previous comment. Jaybird has two URL formats:
* The 'standard' format: jdbc:firebirdsql://host[:port]/db-path
* And the legacy, isql-like format: jdbc:firebirdsql:host[/port]:db-path

You can't combine those two.

@firebird-automations
Copy link
Author

Commented by: @mrotteveel

In conclusion, the problem was with an incorrect JDBC url. When Jaybird parsed the URL it got hostname 192.168.0.201, no port (so defaults to port 3050) and database 3252:employee.

See http://www.firebirdsql.org/file/documentation/drivers_documentation/java/faq.html#pure-java-default

@firebird-automations
Copy link
Author

Modified by: @mrotteveel

status: Open [ 1 ] => Closed [ 6 ]

resolution: Won't Fix [ 2 ]

@firebird-automations
Copy link
Author

Commented by: @pavel-zotov

--- quote beg ---
See my previous comment. Jaybird has two URL formats:
* The 'standard' format: jdbc:firebirdsql://host[:port]/db-path
* And the legacy, isql-like format: jdbc:firebirdsql:host[/port]:db-path

You can't combine those two.
--- quote end ---

Mark,

in what place you see that I *combined* these two type of URL ?
Unfortunatelly, I can see only one thing: "The 'standard' format: jdbc:firebirdsql://host[:port]/db-path" - does NOT work. At all.

Can you please point what exactly wrong in this call:

java -cp .;jaybird-full-2.2.4.jar DriverExample jdbc:firebirdsql://192.168.0.201/3252:employee

-- ?

@firebird-automations
Copy link
Author

Commented by: @mrotteveel

To connect using the standard URL format to 192.168.0.201 on port 3252 you'd need to use:
jdbc:firebirdsql://192.168.0.201:3252/employee

Note the placing of the colon (:) before port and slash (/) after, which is the reverse of what you have in your URL.

The URL you are using is: jdbc:firebirdsql://192.168.0.201/3252:employee
Which is a 'standard' format that breaks down as:
host: 192.168.0.201
port: none specified(!!!), so defaulting to 3050
db-path: 3252:employee

@firebird-automations
Copy link
Author

Commented by: @pavel-zotov

Mark,

thank you very much.

Sorry for my carelessnes: I could see myself this mistake before.

@firebird-automations
Copy link
Author

Commented by: @mrotteveel

No problem; this isn't the first time the two url formats have caused confusion :(

@firebird-automations
Copy link
Author

Commented by: @pavel-zotov

Mark,

you say above that:
---
Jaybird has two URL formats:
* The 'standard' format: jdbc:firebirdsql://host[:port]/db-path
* And the legacy, isql-like format: jdbc:firebirdsql:host[/port]:db-path
---

Does it mean that second variant ( which is "isl-like" ) will be deprecated in the future ?

@firebird-automations
Copy link
Author

Commented by: @mrotteveel

For the time being it will be supported, but its use is discouraged in favor of the standard format as that is more like the URL format of other JDBC drivers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants