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

StompDecoder StringIndexOutOfBoundsException with Apache ActiveMQ [SPR-12418] #17025

Closed
spring-projects-issues opened this issue Nov 9, 2014 · 6 comments
Assignees
Labels
in: messaging Issues in messaging modules (jms, messaging) in: web Issues in web modules (web, webmvc, webflux, websocket) status: backported An issue that has been backported to maintenance branches type: bug A general bug
Milestone

Comments

@spring-projects-issues
Copy link
Collaborator

spring-projects-issues commented Nov 9, 2014

Sang-hyun Lee opened SPR-12418 and commented

I'm using the Spring Framework libraries.


  1. Spring Boot 1.1.8.RELEASE
    1-1. org.springframework.boot:spring-boot-starter-amqp:jar:1.1.8.RELEASE
    1-2. org.springframework.boot:spring-boot-starter-websocket:jar:1.1.8.RELEASE
  2. org.springframework:spring-messaging:jar:4.0.7.RELEASE
  3. org.projectreactor:reactor-net:jar:1.1.4.RELEASE (for StompBrokerRelay)

I referneced http://assets.spring.io/wp/WebSocketBlogPost.html
but I'm using the "Apache ActiveMQ 5.10.0" and configured Stomp Broker Relay.

My Application publishing stomp messages to client 5 ~ 30 messages per second.
each message has 300 ~ 700 bytes length of payload.

I meet "StringIndexOutOfBoundsException" irregularly.
and after connection is closed.

stacktrace is below.


java.lang.StringIndexOutOfBoundsException: String index out of range: 3
at java.lang.String.charAt(String.java:658)
at org.springframework.messaging.simp.stomp.StompDecoder.unescape(StompDecoder.java:221)
at org.springframework.messaging.simp.stomp.StompDecoder.readHeaders(StompDecoder.java:197)
at org.springframework.messaging.simp.stomp.StompDecoder.decodeMessage(StompDecoder.java:123)
at org.springframework.messaging.simp.stomp.StompDecoder.decode(StompDecoder.java:99)
at org.springframework.messaging.simp.stomp.StompDecoder.decode(StompDecoder.java:68)
at org.springframework.messaging.simp.stomp.Reactor11StompCodec$DecodingFunction.apply(Reactor11StompCodec.java:96)
at org.springframework.messaging.simp.stomp.Reactor11StompCodec$DecodingFunction.apply(Reactor11StompCodec.java:83)
at reactor.net.AbstractNetChannel.read(AbstractNetChannel.java:214)
at reactor.net.netty.NettyNetChannelInboundHandler.passToConnection(NettyNetChannelInboundHandler.java:105)
at reactor.net.netty.NettyNetChannelInboundHandler.channelRead(NettyNetChannelInboundHandler.java:69)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:332)
at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:318)
at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:787)
at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:125)
at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:507)
at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:464)
at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:378)
at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:350)
at io.netty.util.concurrent.SingleThreadEventExecutor$2.run(SingleThreadEventExecutor.java:116)
at java.lang.Thread.run(Thread.java:745)


so, I debug the StompDecoder.java (4.0.7.RELEASE source)

and I found out the StompDecoder.unescape() method throws the StringIndexOutOfBoundsException
when message header value end with "". (in my case "message-id" value exactly)

Messages that caused the exception are like below.

CASE #1)


content-type:application/json;charset=UTF-8
message-id:ID
095041.588 ERROR 20569 --- [eactor-tcp-io-4] reactor.core.Reactor : String index out of range: 3
java.lang.StringIndexOutOfBoundsException: String index out of range: 3
at java.lang.String.charAt(String.java:658)
at org.springframework.messaging.simp.stomp.StompDecoder.unescape(StompDecoder.java:221)
at org.springframework.messaging.simp.stomp.StompDecoder.readHeaders(StompDecoder.java:197)
at org.springframework.messaging.simp.stomp.StompDecoder.decodeMessage(StompDecoder.java:123)

... same stack trace...

CASE #2)


content-type:application/json;charset=UTF-8
message-id:ID\cktpdevGW-39005-1415095980735-2\c882\c-1\c1
095056.596 ERROR 20569 --- [eactor-tcp-io-3] reactor.core.Reactor : String index out of range: 47
java.lang.StringIndexOutOfBoundsException: String index out of range: 47
at java.lang.String.charAt(String.java:658)
at org.springframework.messaging.simp.stomp.StompDecoder.unescape(StompDecoder.java:221)
at org.springframework.messaging.simp.stomp.StompDecoder.readHeaders(StompDecoder.java:197)
at org.springframework.messaging.simp.stomp.StompDecoder.decodeMessage(StompDecoder.java:123)

... same stack trace...

CASE #3)


content-type:application/json;charset=UTF-8
message-id:ID\cktpdevGW-39005-1415095980735-2\c882
101513.253 ERROR 20569 --- [eactor-tcp-io-4] reactor.core.Reactor : String index out of range: 40
java.lang.StringIndexOutOfBoundsException: String index out of range: 40
at java.lang.String.charAt(String.java:658)
at org.springframework.messaging.simp.stomp.StompDecoder.unescape(StompDecoder.java:221)
at org.springframework.messaging.simp.stomp.StompDecoder.readHeaders(StompDecoder.java:197)
at org.springframework.messaging.simp.stomp.StompDecoder.decodeMessage(StompDecoder.java:123)

... same stack trace...

every case of messages are ended with "" character.
that messages are looks like incomplete message from the network.

this exception happens on localhost (127.0.0.1 loopback)


Affects: 4.0.7

Issue Links:

Referenced from: commits 1803348, b331d65

Backported to: 4.0.8

@spring-projects-issues
Copy link
Collaborator Author

Sébastien Deleuze commented

Hi, I don't think "" is a valid last character for header values. As stated in STOMP specification, escapes sequences defined by the STOMP protocol are "\r", "\n", "\c" and "", and "Undefined escape sequences [...] MUST be treated as a fatal protocol error".

We could perhaps improve error handling, for example by throwing a StompConversionException instead of this StringIndexOutOfBoundsException, but before I would like to understand how did you get such header value.

Is the message containing this "message-id" header value an AMQP one translated to a STOMP one by ActiveMQ ?

@spring-projects-issues
Copy link
Collaborator Author

Sang-hyun Lee commented

Yes, It's true. "" is not a valid character in STOMP Spec.

Is the message containing this "message-id" header value an AMQP one translated to a STOMP one by ActiveMQ ?
--> Yes, ActiveMQ does. (I configured activemq server for a stomp broker relay and my spring boot application too)
--> but, I don't know how generated such a message-id T.T

I guess the message-id generated by activemq but It seems to has a bug or splitted values in stream-based transport.
(like this article - http://netty.io/wiki/user-guide-for-4.x.html (Dealing with a Stream-based Transport section)).

It just a guess.

@spring-projects-issues
Copy link
Collaborator Author

Sébastien Deleuze commented

Sang-hyun Lee Do you use the RabbitTemplate to send an AMQP message to ActiveMQ ?

@spring-projects-issues
Copy link
Collaborator Author

Sang-hyun Lee commented

I use [1]JmsTemplate (org.springframework.jms.core) to send to ActiveMQ topic.
and use [2]SimpMessageSendingOperations (org.springframework.messaging.simp) to publish to stomp broker relay.

= My Application structure =
MyCommunication-Server -> [1] ActiveMQ Topic -> API Engine -> [2]ActiveMQ Stomp Broker Relay -> User Interface

@spring-projects-issues
Copy link
Collaborator Author

Sébastien Deleuze commented

Ok, maybe a bug in ActiveMQ. However, I have just pushed a fix that will throw a StompConversionException exception instead of the StringIndexOutOfBoundsException one. It will be part of our 4.1.2 and 4.0.8 releases, thanks for your report.

@spring-projects-issues
Copy link
Collaborator Author

Sang-hyun Lee commented

Thank you for your help !!

@spring-projects-issues spring-projects-issues added type: bug A general bug in: messaging Issues in messaging modules (jms, messaging) status: backported An issue that has been backported to maintenance branches in: web Issues in web modules (web, webmvc, webflux, websocket) labels Jan 11, 2019
@spring-projects-issues spring-projects-issues added this to the 4.1.2 milestone Jan 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: messaging Issues in messaging modules (jms, messaging) in: web Issues in web modules (web, webmvc, webflux, websocket) status: backported An issue that has been backported to maintenance branches type: bug A general bug
Projects
None yet
Development

No branches or pull requests

2 participants