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

Connecting to Mongo fails with an UnknownHostException when spring.data.mongodb.additional-hosts is configured #36441

Closed
ghost opened this issue Jul 18, 2023 · 0 comments
Assignees
Labels
type: regression A regression from a previous release
Milestone

Comments

@ghost
Copy link

ghost commented Jul 18, 2023

I have some MongoDB config with Spring boot:

spring:
  data:
    mongodb:
      database: admin
      username: admin
      password: pass
      host: localhost
      additional-hosts: [somehost]

When I start my application, I see the following error in logs:

com.mongodb.MongoSocketException: localhostsomehost
	at com.mongodb.ServerAddress.getSocketAddresses(ServerAddress.java:217) ~[mongodb-driver-core-4.9.1.jar:na]
	at com.mongodb.internal.connection.SocketStream.initializeSocket(SocketStream.java:78) ~[mongodb-driver-core-4.9.1.jar:na]
	at com.mongodb.internal.connection.SocketStream.open(SocketStream.java:68) ~[mongodb-driver-core-4.9.1.jar:na]
	at com.mongodb.internal.connection.InternalStreamConnection.open(InternalStreamConnection.java:204) ~[mongodb-driver-core-4.9.1.jar:na]
	at com.mongodb.internal.connection.DefaultServerMonitor$ServerMonitorRunnable.lookupServerDescription(DefaultServerMonitor.java:199) ~[mongodb-driver-core-4.9.1.jar:na]
	at com.mongodb.internal.connection.DefaultServerMonitor$ServerMonitorRunnable.run(DefaultServerMonitor.java:159) ~[mongodb-driver-core-4.9.1.jar:na]
	at java.base/java.lang.Thread.run(Thread.java:833) ~[na:na]
Caused by: java.net.UnknownHostException: localhostsomehost
	at java.base/java.net.InetAddress$CachedAddresses.get(InetAddress.java:801) ~[na:na]
	at java.base/java.net.InetAddress$NameServiceAddresses.get(InetAddress.java:887) ~[na:na]
	at java.base/java.net.InetAddress.getAllByName0(InetAddress.java:1533) ~[na:na]
	at java.base/java.net.InetAddress.getAllByName(InetAddress.java:1385) ~[na:na]
	at java.base/java.net.InetAddress.getAllByName(InetAddress.java:1306) ~[na:na]
	at com.mongodb.ServerAddress.getSocketAddresses(ServerAddress.java:209) ~[mongodb-driver-core-4.9.1.jar:na]
	... 6 common frames omitted

I've found that in PropertiesMongoConnectionDetails class connection string (getConnectionString() function) is being built and comma is missing between host value and first additional host value:

		builder.append((this.properties.getHost() != null) ? this.properties.getHost() : "localhost");
		if (this.properties.getPort() != null) {
			builder.append(":");
			builder.append(this.properties.getPort());
		}
		if (this.properties.getAdditionalHosts() != null) {
			builder.append(String.join(",", this.properties.getAdditionalHosts()));
		}

String.join(",", this.properties.getAdditionalHosts()) will insert comma between additional-hosts values, but not at the start

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Jul 18, 2023
@wilkinsona wilkinsona added type: regression A regression from a previous release and removed status: waiting-for-triage An issue we've not yet triaged labels Jul 18, 2023
@wilkinsona wilkinsona added this to the 3.1.x milestone Jul 18, 2023
@wilkinsona wilkinsona changed the title MongoDB additional-hosts UnknownHostException Connecting to Mongo fails with an UnknownHostException when spring.data.mongodb.additional-hosts is configured Jul 18, 2023
@wilkinsona wilkinsona self-assigned this Jul 18, 2023
@wilkinsona wilkinsona modified the milestones: 3.1.x, 3.1.2 Jul 18, 2023
ndwlocatieservices added a commit to ndwnu/nls-routing-map-matcher that referenced this issue Nov 3, 2024
This PR contains the following updates:

| Package | Type | Update | Change |
|---|---|---|---|
| [nu.ndw.nls.geometry:nls-geometry](https://spring.io/projects/spring-boot) ([source](https://github.com/spring-projects/spring-boot)) | compile | patch | `3.1.0` -> `3.1.2` |
| [org.springframework.boot:spring-boot-starter-parent](https://spring.io/projects/spring-boot) ([source](https://github.com/spring-projects/spring-boot)) | parent | patch | `3.3.4` -> `3.3.5` |

---

### Release Notes

<details>
<summary>spring-projects/spring-boot (nu.ndw.nls.geometry:nls-geometry)</summary>

### [`v3.1.2`](https://github.com/spring-projects/spring-boot/releases/tag/v3.1.2)

[Compare Source](spring-projects/spring-boot@v3.1.1...v3.1.2)

#### 🐞 Bug Fixes

-   Native reflection hints missing for nested properties declared in a superclass [#&#8203;36448](spring-projects/spring-boot#36448)
-   Connecting to Mongo fails with an UnknownHostException when spring.data.mongodb.additional-hosts is configured [#&#8203;36441](spring-projects/spring-boot#36441)
-   Auto-configured ExemplarSampler bean only backs off when a DefaultExemplarSampler is defined [#&#8203;36429](spring-projects/spring-boot#36429)
-   OTel Span is missing required attributes [#&#8203;36423](spring-projects/spring-boot#36423)
-   Auto-configured JacksonJsonpMapper is conditional on an ObjectMapper bean but does not use such a bean [#&#8203;36409](spring-projects/spring-boot#36409)
-   Application fails to start when `@Import`ing a `@ConfigurationProperties` class that is eligible for constructor binding [#&#8203;36359](spring-projects/spring-boot#36359)
-   Only one health group can be exposed using management.endpoint.health.group.xxx.additional-path=server:/newpath when using Jersey [#&#8203;36276](spring-projects/spring-boot#36276)
-   Mongo auto-configuration fails when username or password properties contains a colon (`:`) or at-sign (`@`) [#&#8203;36261](spring-projects/spring-boot#36261)
-   MockitoPostProcessor doesn't check FactoryBean.OBJECT_TYPE_ATTRIBUTE correctly [#&#8203;36230](spring-projects/spring-boot#36230)
-   ImportsContextCustomizer does not support AliasFor [#&#8203;36209](spring-projects/spring-boot#36209)
-   Saml2RelyingPartyRegistrationConfiguration can choose the wrong RelyingPartyRegistration.Builder when using a metadata file with multiple providers [#&#8203;36163](spring-projects/spring-boot#36163)
-   ConfigurationPropertiesReportEndpoint does not display primitive wrapper types [#&#8203;36160](spring-projects/spring-boot#36160)
-   ConfigurationPropertyName#equals is not symmetric when element has trailing dashes [#&#8203...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: regression A regression from a previous release
Projects
None yet
Development

No branches or pull requests

2 participants