Skip to content

JAVA-6071 use trampoline pattern to avoid stackoverflow in reactive driver #1973

Open
strogiyotec wants to merge 1 commit into
mongodb:mainfrom
strogiyotec:JAVA-6071
Open

JAVA-6071 use trampoline pattern to avoid stackoverflow in reactive driver #1973
strogiyotec wants to merge 1 commit into
mongodb:mainfrom
strogiyotec:JAVA-6071

Conversation

@strogiyotec
Copy link
Copy Markdown
Contributor

@strogiyotec strogiyotec commented May 18, 2026

JAVA-6071
the AsynchronousChannelStream was rewritten to use thenRunWhileLoop instead of BasicCompletionHandler that caused a stackoverflow

thenRunWhileLoop internally uses TRAMPOLINE to avoid increased stacktraces

How it was tested

Start mongodb in tls mode

mongod --tlsMode requireTLS --tlsCertificateKeyFile ~/mongodb-ssl/server.pem --tlsCAFile ~/mongodb-ssl/ca.crt --tlsAllowConnectionsWithoutCertificates

Run test case com.mongodb.reactivestreams.client.CrudProseTest.testBulkWriteHandlesWriteErrorsAcrossBatches

  1. set ordered=false
  2. pass -Xss512k to decrease stack size
  3. pass -Dorg.mongodb.test.uri="mongodb://localhost:27017/?tls=true&tlsAllowInvalidHostnames=true&tlsCAFile=/home/almas/mongodb-ssl/ca.crt" to connect to TLS mongo

Additionally we can set an eval at AsyncTrampoline#65 to System.out.println("Depth"+ Thread.currentThread().getStackTrace().length) and verify that printed number is not growing

@strogiyotec strogiyotec requested a review from vbabanin May 18, 2026 05:28
@strogiyotec strogiyotec requested a review from a team as a code owner May 18, 2026 05:28
@strogiyotec strogiyotec changed the title JAVA-6071 JAVA-6071 use trampoline pattern to avoid stackoverflow in reactive driver May 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant