Skip to content

DATAREDIS-1027 - Dispose reactive LettuceConnectionProvider on connection factory shutdown #470

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

Closed
wants to merge 2 commits into from
Closed
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
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<groupId>org.springframework.data</groupId>
<artifactId>spring-data-redis</artifactId>
<version>2.2.0.BUILD-SNAPSHOT</version>
<version>2.2.0.DATAREDIS-1027-SNAPSHOT</version>

<name>Spring Data Redis</name>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -299,16 +299,8 @@ public void destroy() {

resetConnection();

if (connectionProvider instanceof DisposableBean) {
try {
((DisposableBean) connectionProvider).destroy();
} catch (Exception e) {

if (log.isWarnEnabled()) {
log.warn(connectionProvider + " did not shut down gracefully.", e);
}
}
}
dispose(connectionProvider);
dispose(reactiveConnectionProvider);

try {
Duration quietPeriod = clientConfiguration.getShutdownQuietPeriod();
Expand All @@ -332,6 +324,20 @@ public void destroy() {
}
}

private void dispose(LettuceConnectionProvider connectionProvider) {

if (connectionProvider instanceof DisposableBean) {
try {
((DisposableBean) connectionProvider).destroy();
} catch (Exception e) {

if (log.isWarnEnabled()) {
log.warn(connectionProvider + " did not shut down gracefully.", e);
}
}
}
}

/*
* (non-Javadoc)
* @see org.springframework.data.redis.connection.RedisConnectionFactory#getConnection()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
import org.mockito.ArgumentMatchers;

import org.springframework.beans.DirectFieldAccessor;
import org.springframework.beans.factory.DisposableBean;
import org.springframework.data.redis.ConnectionFactoryTracker;
import org.springframework.data.redis.connection.RedisClusterConfiguration;
import org.springframework.data.redis.connection.RedisClusterConnection;
Expand Down Expand Up @@ -805,6 +806,25 @@ protected LettuceConnectionProvider doCreateConnectionProvider(AbstractRedisClie
verify(connectionProviderMock, times(2)).getConnection(StatefulConnection.class);
}

@Test // DATAREDIS-1027
public void shouldDisposeConnectionProviders() throws Exception {

LettuceConnectionProvider connectionProviderMock = mock(LettuceConnectionProvider.class,
withSettings().extraInterfaces(DisposableBean.class));
LettuceConnectionFactory connectionFactory = new LettuceConnectionFactory() {
@Override
protected LettuceConnectionProvider doCreateConnectionProvider(AbstractRedisClient client,
RedisCodec<?, ?> codec) {
return connectionProviderMock;
}
};

connectionFactory.afterPropertiesSet();
connectionFactory.destroy();

verify((DisposableBean) connectionProviderMock, times(2)).destroy();
}

@Test // DATAREDIS-842
public void databaseShouldBeSetCorrectlyOnSentinelClient() {

Expand Down