Skip to content

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

Closed
@spring-projects-issues

Description

@spring-projects-issues

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

Metadata

Metadata

Assignees

Labels

in: messagingIssues in messaging modules (jms, messaging)in: webIssues in web modules (web, webmvc, webflux, websocket)status: backportedAn issue that has been backported to maintenance branchestype: bugA general bug

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions