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 #723

Closed
jayzch opened this issue Mar 16, 2018 · 7 comments
Closed

NullPointerException #723

jayzch opened this issue Mar 16, 2018 · 7 comments
Assignees

Comments

@jayzch
Copy link

jayzch commented Mar 16, 2018

Caused by: java.lang.NullPointerException: null at
org.springframework.amqp.rabbit.connection.SimpleConnection.createChannel(SimpleConnection.java:59) at org.springframework.amqp.rabbit.connection.CachingConnectionFactory$ChannelCachingConnectionProxy.createBareChannel(CachingConnectionFactory.java:1156) at org.springframework.amqp.rabbit.connection.CachingConnectionFactory$ChannelCachingConnectionProxy.access$200(CachingConnectionFactory.java:1144) at org.springframework.amqp.rabbit.connection.CachingConnectionFactory.doCreateBareChannel(CachingConnectionFactory.java:585) at org.springframework.amqp.rabbit.connection.CachingConnectionFactory.createBareChannel(CachingConnectionFactory.java:568) at org.springframework.amqp.rabbit.connection.CachingConnectionFactory.getCachedChannelProxy(CachingConnectionFactory.java:538) at org.springframework.amqp.rabbit.connection.CachingConnectionFactory.getChannel(CachingConnectionFactory.java:520) at org.springframework.amqp.rabbit.connection.CachingConnectionFactory.access$1500(CachingConnectionFactory.java:94) at org.springframework.amqp.rabbit.connection.CachingConnectionFactory$ChannelCachingConnectionProxy.createChannel(CachingConnectionFactory.java:1161) at org.springframework.amqp.rabbit.connection.ConnectionFactoryUtils$1.createChannel(ConnectionFactoryUtils.java:112) at org.springframework.amqp.rabbit.connection.ConnectionFactoryUtils.doGetTransactionalResourceHolder(ConnectionFactoryUtils.java:173) at org.springframework.amqp.rabbit.connection.ConnectionFactoryUtils.getTransactionalResourceHolder(ConnectionFactoryUtils.java:92) at org.springframework.amqp.rabbit.core.RabbitTemplate.doExecute(RabbitTemplate.java:1802) at org.springframework.amqp.rabbit.core.RabbitTemplate.execute(RabbitTemplate.java:1784) at org.springframework.amqp.rabbit.core.RabbitTemplate.send(RabbitTemplate.java:864) at org.springframework.amqp.rabbit.core.RabbitTemplate.convertAndSend(RabbitTemplate.java:927) at org.springframework.amqp.rabbit.core.RabbitTemplate.convertAndSend(RabbitTemplate.java:910) at

@garyrussell
Copy link
Contributor

That implies the underlying rabbit connection returned no channel, which should not be possible.

Please show your configuration. the code that exhibits this behavior, together with version information for all libraries.

@jayzch
Copy link
Author

jayzch commented Mar 16, 2018

    <spring-amqp.version>2.0.2.RELEASE</spring-amqp.version>

I changed different rabbit mq server .
At First , a number of servers conneted to the same RabbitMQ Server.
The problem occur when I connect to this RabbitMQ Server where maxChannel = 10
image
The problem disappeared when I connect to this RabbitMQ Server where maxChannel = 0

image

And then I solved the problem by setting maxChannel to 0.

But I think the framework should not threw NullPointerException.

@artembilan
Copy link
Member

Not clear, what you show to us, @jayzch .
That's why Gary asked about some code to reproduce.

Indeed, Framework should not throw NPE, but you see your comment is not readable and we can't understand that stack trace properly. If you could format it the standard console output way, that would be helpful. Anyway +1 for some code to reproduce. Otherwise neither we can help you, nor you for us to fix the problem if it is there.

Thank you for understanding.

@jayzch
Copy link
Author

jayzch commented Mar 16, 2018

This problem occurs when the number of RabbitMQ Server channels exceeds the limit maxChannel

@artembilan
Copy link
Member

OK! Let it be. But how to reproduce, please?
Why also don't edit the mentioned stack trace to help us to read it clearly?

jayzch added a commit to jayzch/spring-amqp that referenced this issue Mar 16, 2018
@garyrussell
Copy link
Contributor

It's a bit odd that the client returns null in this case rather than throwing an exception.

I think the assertion should be made regardless of whether a transaction is being used.

@garyrussell
Copy link
Contributor

It is odd, indeed, but clear in the javadocs...

/**
 * Create a new channel, using an internally allocated channel number.
 * If <a href="http://www.rabbitmq.com/api-guide.html#recovery">automatic connection recovery</a>
 * is enabled, the channel returned by this method will be {@link Recoverable}.
 *
 * @return a new channel descriptor, or null if none is available
 * @throws IOException if an I/O problem is encountered
 */
Channel createChannel() throws IOException;

jayzch added a commit to jayzch/spring-amqp that referenced this issue Mar 16, 2018
jayzch added a commit to jayzch/spring-amqp that referenced this issue Mar 16, 2018
jayzch added a commit to jayzch/spring-amqp that referenced this issue Mar 19, 2018
@artembilan artembilan self-assigned this Apr 3, 2018
artembilan added a commit to artembilan/spring-amqp that referenced this issue Apr 3, 2018
Fixes spring-projects#723

To avoid an `NPE` when connection returns `null` for the
`createChannel()` in case of `channelMax` is reached, throw newly
introduced `AmqpResourceNotAvailableException`.
This exception can be used in the `RetryPolicy` to retry the original
operation after some back-off - the channel permit may be released in
between

**Cherry-pick to 2.0.x and 1.7.x**
garyrussell pushed a commit that referenced this issue Apr 3, 2018
* GH-723: Add AmqpResourceNotAvailableException

Fixes #723

To avoid an `NPE` when connection returns `null` for the
`createChannel()` in case of `channelMax` is reached, throw newly
introduced `AmqpResourceNotAvailableException`.
This exception can be used in the `RetryPolicy` to retry the original
operation after some back-off - the channel permit may be released in
between

**Cherry-pick to 2.0.x and 1.7.x**

* * Fix `AbstractConnectionFactoryTests` for proper mock
* Fix `amqp.adoc` according PR comments
garyrussell pushed a commit that referenced this issue Apr 3, 2018
* GH-723: Add AmqpResourceNotAvailableException

Fixes #723

To avoid an `NPE` when connection returns `null` for the
`createChannel()` in case of `channelMax` is reached, throw newly
introduced `AmqpResourceNotAvailableException`.
This exception can be used in the `RetryPolicy` to retry the original
operation after some back-off - the channel permit may be released in
between

**Cherry-pick to 2.0.x and 1.7.x**

* * Fix `AbstractConnectionFactoryTests` for proper mock
* Fix `amqp.adoc` according PR comments
garyrussell pushed a commit that referenced this issue Apr 3, 2018
* GH-723: Add AmqpResourceNotAvailableException

Fixes #723

To avoid an `NPE` when connection returns `null` for the
`createChannel()` in case of `channelMax` is reached, throw newly
introduced `AmqpResourceNotAvailableException`.
This exception can be used in the `RetryPolicy` to retry the original
operation after some back-off - the channel permit may be released in
between

**Cherry-pick to 2.0.x and 1.7.x**

* * Fix `AbstractConnectionFactoryTests` for proper mock
* Fix `amqp.adoc` according PR comments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants