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

NullPointerException when RedisLockRegistry is destroyed #3888

Closed
arn-rio opened this issue Sep 20, 2022 · 2 comments · Fixed by #3889
Closed

NullPointerException when RedisLockRegistry is destroyed #3888

arn-rio opened this issue Sep 20, 2022 · 2 comments · Fixed by #3889

Comments

@arn-rio
Copy link

arn-rio commented Sep 20, 2022

In what version(s) of Spring Integration are you seeing this issue?

5.5.14

Describe the bug

During spring shutdown, a Null Pointer exception is thrown when the RedisLockRegistry is destroyed (because the redisMessageListenerContainer attribute is null).

To Reproduce

Run the following application. When shutting down, this warning message is logged :

2022-09-19 18:13:53.065 WARN 2260 --- [ionShutdownHook] o.s.b.f.support.DisposableBeanAdapter : Invocation of destroy method failed on bean with name 'redisLockRegistry': java.lang.IllegalStateException: java.lang.NullPointerException

Expected behavior

It seems possible that there is no instance of redisMessageListenerContainer. We may check that the listener exists before calling destroy on it.

Sample

demo.zip

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
	<modelVersion>4.0.0</modelVersion>
	<parent>
		<groupId>org.springframework.boot</groupId>
		<artifactId>spring-boot-starter-parent</artifactId>
		<version>2.7.3</version>
		<relativePath/> <!-- lookup parent from repository -->
	</parent>
	<groupId>com.example</groupId>
	<artifactId>demo</artifactId>
	<version>0.0.1-SNAPSHOT</version>
	<name>demo</name>
	<description>Demo project for Spring Boot</description>
	<properties>
		<java.version>1.8</java.version>
	</properties>
	<dependencies>
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter</artifactId>
		</dependency>
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-test</artifactId>
			<scope>test</scope>
		</dependency>
		<dependency>
			<groupId>org.springframework.integration</groupId>
			<artifactId>spring-integration-redis</artifactId>
		</dependency>
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-data-redis</artifactId>
			<exclusions>
				<exclusion>
					<groupId>io.lettuce</groupId>
					<artifactId>lettuce-core</artifactId>
				</exclusion>
			</exclusions>
		</dependency>
		<dependency>
			<groupId>redis.clients</groupId>
			<artifactId>jedis</artifactId>
			<version>3.8.0</version>
		</dependency>
	</dependencies>
	<build>
		<plugins>
			<plugin>
				<groupId>org.springframework.boot</groupId>
				<artifactId>spring-boot-maven-plugin</artifactId>
			</plugin>
		</plugins>
	</build>

</project>
package com.example.demo;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.data.redis.RedisProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.data.redis.connection.RedisStandaloneConfiguration;
import org.springframework.data.redis.connection.jedis.JedisConnectionFactory;
import org.springframework.integration.redis.util.RedisLockRegistry;

@SpringBootApplication
public class DemoApplication {

	private String LOCK_NAME = "lock";

	@Bean
	public RedisLockRegistry redisLockRegistry(RedisProperties redisProperties) {
		RedisStandaloneConfiguration redisStandaloneConfiguration = new RedisStandaloneConfiguration(
				"localhost", 6379);
		JedisConnectionFactory jedisConnectionFactory = new JedisConnectionFactory(redisStandaloneConfiguration);
		jedisConnectionFactory.afterPropertiesSet();
		return new RedisLockRegistry(jedisConnectionFactory, LOCK_NAME);
	}

	public static void main(String[] args) {
		SpringApplication.run(DemoApplication.class, args);
	}

}
@arn-rio arn-rio added status: waiting-for-triage The issue need to be evaluated and its future decided type: bug labels Sep 20, 2022
@artembilan artembilan added this to the 6.0.0-M5 milestone Sep 20, 2022
@artembilan artembilan added in: redis backport 5.5.x and removed status: waiting-for-triage The issue need to be evaluated and its future decided labels Sep 20, 2022
@artembilan
Copy link
Member

Confirmed.
Will be fixed soon.

Thank you!

artembilan added a commit to artembilan/spring-integration that referenced this issue Sep 20, 2022
Fixed spring-projects#3888

When `RedisLockType.SPIN_LOCK` (default), the `RedisLockRegistry.destroy()`
causes an NPE on the `redisMessageListenerContainer` since pub-sub is not used
in a busy-spin mode

* Check for `redisMessageListenerContainer` before calling its `destroy()`

**Cherry-pick to 5.5.x**
artembilan added a commit to artembilan/spring-integration that referenced this issue Sep 20, 2022
Fixed spring-projects#3888

When `RedisLockType.SPIN_LOCK` (default), the `RedisLockRegistry.destroy()`
causes an NPE on the `redisMessageListenerContainer` since pub-sub is not used
in a busy-spin mode

* Check for `redisMessageListenerContainer` before calling its `destroy()`

**Cherry-pick to 5.5.x**
garyrussell pushed a commit that referenced this issue Sep 20, 2022
* GH-3888: Fix NPE in the `RedisLockRegistry.destroy()`

Fixed #3888

When `RedisLockType.SPIN_LOCK` (default), the `RedisLockRegistry.destroy()`
causes an NPE on the `redisMessageListenerContainer` since pub-sub is not used
in a busy-spin mode

* Check for `redisMessageListenerContainer` before calling its `destroy()`

**Cherry-pick to 5.5.x**

* * Reset properties in the `RedisLockRegistry` after `destroy()`
garyrussell pushed a commit that referenced this issue Sep 20, 2022
* GH-3888: Fix NPE in the `RedisLockRegistry.destroy()`

Fixed #3888

When `RedisLockType.SPIN_LOCK` (default), the `RedisLockRegistry.destroy()`
causes an NPE on the `redisMessageListenerContainer` since pub-sub is not used
in a busy-spin mode

* Check for `redisMessageListenerContainer` before calling its `destroy()`

**Cherry-pick to 5.5.x**

* * Reset properties in the `RedisLockRegistry` after `destroy()`
@arn-rio
Copy link
Author

arn-rio commented Sep 21, 2022

Thanks for the fix and the release.

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

Successfully merging a pull request may close this issue.

2 participants