Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import org.apache.dubbo.common.utils.IOUtils;

import java.io.IOException;
import java.io.InputStream;
import java.util.Objects;

@Activate(order = Integer.MAX_VALUE - 10000)
Expand All @@ -53,10 +54,10 @@ public ProviderCert getProviderConnectionConfig(URL localAddress) {
.map(sslConfig -> {
try {
return new ProviderCert(
IOUtils.toByteArray(sslConfig.getServerKeyCertChainPathStream()),
IOUtils.toByteArray(sslConfig.getServerPrivateKeyPathStream()),
readAll(sslConfig.getServerKeyCertChainPathStream()),
readAll(sslConfig.getServerPrivateKeyPathStream()),
sslConfig.getServerTrustCertCollectionPath() != null
? IOUtils.toByteArray(sslConfig.getServerTrustCertCollectionPathStream())
? readAll(sslConfig.getServerTrustCertCollectionPathStream())
: null,
sslConfig.getServerKeyPassword(),
AuthPolicy.CLIENT_AUTH);
Expand Down Expand Up @@ -84,10 +85,10 @@ public Cert getConsumerConnectionConfig(URL remoteAddress) {
.map(sslConfig -> {
try {
return new Cert(
IOUtils.toByteArray(sslConfig.getClientKeyCertChainPathStream()),
IOUtils.toByteArray(sslConfig.getClientPrivateKeyPathStream()),
readAll(sslConfig.getClientKeyCertChainPathStream()),
readAll(sslConfig.getClientPrivateKeyPathStream()),
sslConfig.getClientTrustCertCollectionPath() != null
? IOUtils.toByteArray(sslConfig.getClientTrustCertCollectionPathStream())
? readAll(sslConfig.getClientTrustCertCollectionPathStream())
: null,
sslConfig.getClientKeyPassword());
} catch (IOException e) {
Expand All @@ -102,4 +103,15 @@ public Cert getConsumerConnectionConfig(URL remoteAddress) {
})
.orElse(null);
}

/**
* Reads the stream into memory and closes it. The streams returned by {@code SslConfig} are
* file-backed; leaving them open keeps the underlying files locked on Windows and blocks
* deletion of the containing directory.
*/
private byte[] readAll(InputStream inputStream) throws IOException {
try (InputStream stream = inputStream) {
return IOUtils.toByteArray(stream);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import java.util.Map;
import java.util.concurrent.Executor;

import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Test;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;
Expand All @@ -40,6 +41,13 @@

public class AnnotationIsolationTest extends BaseTest {

// SysProps set inside the test would otherwise leak into other test classes running in the
// same JVM: Dubbo resolves dubbo.metrics.* from System properties with the highest precedence.
@AfterEach
public void afterEach() {
SysProps.clear();
}

@Test
public void test() throws Exception {
SysProps.clear();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,14 @@ public class SpringBootConfigMetricsTest {

@BeforeAll
public static void beforeAll() {
// Clear JVM System properties that other tests in the same JVM may have left set to
// disable metrics. Dubbo resolves dubbo.metrics.* from the System properties with the
// highest precedence, which would otherwise override this test's @SpringBootTest
// property dubbo.metrics.protocol=prometheus and fail the assertion below.
// See SpringBootConfigPropsTest for the same guard and AnnotationIsolationTest, which
// previously leaked these properties (now cleaned up in its @AfterEach).
System.clearProperty("dubbo.metrics.protocol");
System.clearProperty("dubbo.metrics.enabled");
DubboBootstrap.reset();
}

Expand Down
Loading