The JDBC driver tries to handle this by estimating how much data has been buffered. It mainly comes up when executing batch INSERTS as a large number of statements may be sent to the backend prior to reading back any results.
There's a nice write up of the potential deadlock and the driver's logic to avoid it here: