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

Connection url with multiple hosts is not supported #179

Closed
legoethals opened this issue Sep 2, 2020 · 2 comments
Closed

Connection url with multiple hosts is not supported #179

legoethals opened this issue Sep 2, 2020 · 2 comments
Labels
status: invalid An issue that we don't feel is valid

Comments

@legoethals
Copy link

Bug Report

Versions

  • io.r2dbc:r2dbc-spi:0.8.2.RELEASE
  • io.r2dbc:r2dbc-pool:0.8.3.RELEASE
  • io.r2dbc:r2dbc-postgresql:0.8.4.RELEASE

Current Behavior

When a connection url with multiple hosts, e.g. r2dbc:postgresql://host1:5432,host2:5432/db_name, is used for setup through spring application properties, connections cannot be made to the given hosts. An exception is thrown instead: io.r2dbc.postgresql.PostgresqlConnectionFactory$PostgresConnectionException: Cannot connect to host1:5432,host2:5432:5432

Example configuration

spring.r2dbc.url=r2dbc:postgresql://host1:5432,host2:5432/db_name
spring.r2dbc.username=user
spring.r2dbc.password=password

Expected behavior/code

According to the spec, the authority part of the url can contain multiple hosts. I would expect a connection to be made to the first host, and if this connection fails, an attempt is made to connect to the next host in the list, moving on until a connection has been made successfully, or until there is no next host to try.

Possible Solution

Provide actual support for multiple hosts with failover capabilities. This would require quite some changes in the ConnectionUrlParser, ConnectionFactoryOptions, ConnectionFactoryProvider implementation and a
ConnectionFactory implementation that supports failover.

@mp911de
Copy link
Member

mp911de commented Sep 3, 2020

When parsing a connection url, then multiple hosts are parsed into the host option (see ConnectionUrlParserUnitTests). Whether a driver support multiple hosts or just a single one is up to the actual driver.

Adding a link to the Postgres R2DBC issue for reference: pgjdbc/r2dbc-postgresql#120.

That being said, there's nothing we can do about individual driver feature sets on the specification level.

@mp911de mp911de closed this as completed Sep 3, 2020
@mp911de mp911de added the status: invalid An issue that we don't feel is valid label Sep 3, 2020
@kotoant
Copy link

kotoant commented Jan 22, 2021

Here is the solution, that works without any changes in ConnectionUrlParser, ConnectionFactoryOptions, ConnectionFactoryProvider implementation. It also works with any driver (not only postgresql).

pgjdbc/r2dbc-postgresql#120 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: invalid An issue that we don't feel is valid
Projects
None yet
Development

No branches or pull requests

3 participants