TLS inPlain buffer overflow error hangs indefinitely in scala/java driver 4.1.0

We are using the scala driver version 4.1.0 with TLS enabled. Our application runs smoothly for several hours before randomly erroring with the following log:

2020-08-19 04:08:50.628 | ERROR |  | 9818284 ms| c.m.i.c.t.a.AsynchronousTlsChannelGroup  | error in operation
java.lang.IllegalStateException: inPlain buffer insufficient despite having capacity of 32768
    at com.mongodb.internal.connection.tlschannel.impl.BufferHolder.enlarge(
    at com.mongodb.internal.connection.tlschannel.impl.TlsChannelImpl.unwrapLoop(
    at com.mongodb.internal.connection.tlschannel.impl.TlsChannelImpl.readAndUnwrap(
    at com.mongodb.internal.connection.tlschannel.async.AsynchronousTlsChannelGroup.readHandlingTasks(
    at com.mongodb.internal.connection.tlschannel.async.AsynchronousTlsChannelGroup.doRead(
    at com.mongodb.internal.connection.tlschannel.async.AsynchronousTlsChannelGroup.lambda$processRead$5(
    at java.util.concurrent.ThreadPoolExecutor.runWorker(
    at java.util.concurrent.ThreadPoolExecutor$

this error is thrown at

and logged by

The problem is, after this error is thrown, the Future never completes and the thread hangs indefinitely. No exception is thrown for us to recover from, and our application grinds to a halt.

The error occurs at random, we have not been able to reproduce it on demand.

We thought this was related to / but upgrading the driver to 4.1.0 did not fix the problem. It sounds related because the pending read operation appears to hang indefinitely, and if it is related to unexpected network / socket issues then it would be difficult to reproduce.

HI @Ryan_Foltz,

Thanks for posting, this is something we’d need to look into to understand more about what is happening here. Could you post a ticket to the JAVA jira project.

Looks like there is a bug in the tlschannel library.


Thanks, I’ll open the ticket in a minute.

For the record, we worked around this by configuring a 10 second socket timeout. We still see the error occasionally, but it no longer brings everything to a halt.