StackOverflowError mongo extension

i use axonframe with mongo as event store.

i saw stackoverflow error. but i don’t know why it happens and what’s wrong from my code.

can anyone help me?

Exception in thread "EventProcessor[XXXProcessor]-0" java.lang.StackOverflowError
at org.bson.BsonBinaryWriter.backpatchSize(BsonBinaryWriter.java:413)
at org.bson.BsonBinaryWriter.doWriteEndDocument(BsonBinaryWriter.java:133)
at org.bson.AbstractBsonWriter.writeEndDocument(AbstractBsonWriter.java:307)
at com.mongodb.internal.connection.BsonWriterDecorator.writeEndDocument(BsonWriterDecorator.java:53)
at com.mongodb.internal.connection.LevelCountingBsonWriter.writeEndDocument(LevelCountingBsonWriter.java:48)
at com.mongodb.internal.connection.ElementExtendingBsonWriter.writeEndDocument(ElementExtendingBsonWriter.java:43)
at org.bson.codecs.BsonDocumentCodec.encode(BsonDocumentCodec.java:118)
at org.bson.codecs.BsonDocumentCodec.encode(BsonDocumentCodec.java:41)
at org.bson.internal.LazyCodec.encode(LazyCodec.java:38)
at org.bson.codecs.EncoderContext.encodeWithChildContext(EncoderContext.java:91)
at org.bson.codecs.BsonDocumentCodec.writeValue(BsonDocumentCodec.java:136)
at org.bson.codecs.BsonDocumentCodec.encode(BsonDocumentCodec.java:115)
at org.bson.codecs.BsonDocumentCodec.encode(BsonDocumentCodec.java:41)
at org.bson.internal.LazyCodec.encode(LazyCodec.java:38)
at org.bson.codecs.EncoderContext.encodeWithChildContext(EncoderContext.java:91)
at org.bson.codecs.BsonArrayCodec.encode(BsonArrayCodec.java:82)
at org.bson.codecs.BsonArrayCodec.encode(BsonArrayCodec.java:37)
at org.bson.codecs.EncoderContext.encodeWithChildContext(EncoderContext.java:91)
at org.bson.codecs.BsonDocumentCodec.writeValue(BsonDocumentCodec.java:136)
at org.bson.codecs.BsonDocumentCodec.encode(BsonDocumentCodec.java:115)
at org.bson.codecs.BsonDocumentCodec.encode(BsonDocumentCodec.java:41)
at org.bson.internal.LazyCodec.encode(LazyCodec.java:38)
at org.bson.codecs.EncoderContext.encodeWithChildContext(EncoderContext.java:91)
at org.bson.codecs.BsonArrayCodec.encode(BsonArrayCodec.java:82)
at org.bson.codecs.BsonArrayCodec.encode(BsonArrayCodec.java:37)
at org.bson.codecs.EncoderContext.encodeWithChildContext(EncoderContext.java:91)
at org.bson.codecs.BsonDocumentCodec.writeValue(BsonDocumentCodec.java:136)
at org.bson.codecs.BsonDocumentCodec.encode(BsonDocumentCodec.java:115)
at org.bson.codecs.BsonDocumentCodec.encode(BsonDocumentCodec.java:41)
at org.bson.internal.LazyCodec.encode(LazyCodec.java:38)
at org.bson.codecs.EncoderContext.encodeWithChildContext(EncoderContext.java:91)
at org.bson.codecs.BsonDocumentCodec.writeValue(BsonDocumentCodec.java:136)
at org.bson.codecs.BsonDocumentCodec.encode(BsonDocumentCodec.java:115)
at org.bson.codecs.BsonDocumentCodec.encode(BsonDocumentCodec.java:41)
at com.mongodb.internal.connection.RequestMessage.addDocument(RequestMessage.java:238)
at com.mongodb.internal.connection.RequestMessage.addDocument(RequestMessage.java:188)
at com.mongodb.internal.connection.CommandMessage.encodeMessageBodyWithMetadata(CommandMessage.java:138)
at com.mongodb.internal.connection.RequestMessage.encode(RequestMessage.java:138)
at com.mongodb.internal.connection.CommandMessage.encode(CommandMessage.java:59)
at com.mongodb.internal.connection.InternalStreamConnection.sendAndReceive(InternalStreamConnection.java:247)
at com.mongodb.internal.connection.UsageTrackingInternalConnection.sendAndReceive(UsageTrackingInternalConnection.java:99)
at com.mongodb.internal.connection.DefaultConnectionPool$PooledConnection.sendAndReceive(DefaultConnectionPool.java:500)
at com.mongodb.internal.connection.CommandProtocolImpl.execute(CommandProtocolImpl.java:71)
at com.mongodb.internal.connection.DefaultServer$DefaultServerProtocolExecutor.execute(DefaultServer.java:224)
at com.mongodb.internal.connection.DefaultServerConnection.executeProtocol(DefaultServerConnection.java:202)
at com.mongodb.internal.connection.DefaultServerConnection.command(DefaultServerConnection.java:118)
at com.mongodb.internal.connection.DefaultServerConnection.command(DefaultServerConnection.java:110)
at com.mongodb.internal.operation.CommandOperationHelper$13.call(CommandOperationHelper.java:710)
at com.mongodb.internal.operation.OperationHelper.withReleasableConnection(OperationHelper.java:500)
at com.mongodb.internal.operation.CommandOperationHelper.executeRetryableCommand(CommandOperationHelper.java:703)
at com.mongodb.internal.operation.CommandOperationHelper.executeRetryableCommand(CommandOperationHelper.java:695)
at com.mongodb.internal.operation.BaseFindAndModifyOperation.execute(BaseFindAndModifyOperation.java:69)
at com.mongodb.client.internal.MongoClientDelegate$DelegateOperationExecutor.execute(MongoClientDelegate.java:195)
at com.mongodb.client.internal.MongoCollectionImpl.executeFindOneAndUpdate(MongoCollectionImpl.java:752)
at com.mongodb.client.internal.MongoCollectionImpl.findOneAndUpdate(MongoCollectionImpl.java:732)
at org.axonframework.extensions.mongo.eventsourcing.tokenstore.MongoTokenStore.loadToken(MongoTokenStore.java:184)
at org.axonframework.extensions.mongo.eventsourcing.tokenstore.MongoTokenStore.fetchToken(MongoTokenStore.java:179)
at org.axonframework.eventhandling.TrackingEventProcessor$WorkerLauncher.lambda$run$2(TrackingEventProcessor.java:1096)
at org.axonframework.common.transaction.TransactionManager.executeInTransaction(TransactionManager.java:47)
at org.axonframework.eventhandling.TrackingEventProcessor$WorkerLauncher.run(TrackingEventProcessor.java:1095)
at org.axonframework.eventhandling.TrackingEventProcessor$TrackingSegmentWorker.run(TrackingEventProcessor.java:1031)
at org.axonframework.eventhandling.TrackingEventProcessor$WorkerLauncher.run(TrackingEventProcessor.java:1162)
at org.axonframework.eventhandling.TrackingEventProcessor$TrackingSegmentWorker.run(TrackingEventProcessor.java:1031)
at org.axonframework.eventhandling.TrackingEventProcessor$WorkerLauncher.run(TrackingEventProcessor.java:1162)
at org.axonframework.eventhandling.TrackingEventProcessor$TrackingSegmentWorker.run(TrackingEventProcessor.java:1031)
at org.axonframework.eventhandling.TrackingEventProcessor$WorkerLauncher.run(TrackingEventProcessor.java:1162)
at org.axonframework.eventhandling.TrackingEventProcessor$TrackingSegmentWorker.run(TrackingEventProcessor.java:1031)
at org.axonframework.eventhandling.TrackingEventProcessor$WorkerLauncher.run(TrackingEventProcessor.java:1162)
at org.axonframework.eventhandling.TrackingEventProcessor$TrackingSegmentWorker.run(TrackingEventProcessor.java:1031)
at org.axonframework.eventhandling.TrackingEventProcessor$WorkerLauncher.run(TrackingEventProcessor.java:1162)
at org.axonframework.eventhandling.TrackingEventProcessor$TrackingSegmentWorker.run(TrackingEventProcessor.java:1031)

It might be useful to share the code fragments causing problems an show what you are doing.
Without knowing what you are trying, it becomes difficult to answer questions :wink:

First Axon ‘error’ entry


at org.axonframework.extensions.mongo.eventsourcing.tokenstore.MongoTokenStore.loadToken(MongoTokenStore.java:184)

suggests that your token is too big to be loaded in memory!

Can you check on your Mongo the size of the token document?

KR,

@lfgcampos thank you to let me know!

because of size of the token document, this error would be occurred?

than i wonder that i wouldn’t get error every time (load token).

i know that hard disk size is not enough, so mongoexception keep showing.

but this stackoverflowerror is not coming right after mongoexception.

i can only see two or three times, while mongoexception(size exception) occurred over 1000 times.

please can you let me know why this is happen only few times??

this error is not familiar so i want to know what reason can make it.

thank you!