Skip to content

Commit 8935542

Browse files
authored
Merge pull request #389 from ali-ince/1.1-tlschannel-enlarge-buffer-fix
fix for failed to enlarge network buffer error
2 parents ce3ac75 + a78e441 commit 8935542

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

driver/src/main/java/org/neo4j/driver/internal/security/TLSSocketChannel.java

+12-8
Original file line numberDiff line numberDiff line change
@@ -345,18 +345,22 @@ private HandshakeStatus wrap( ByteBuffer buffer ) throws IOException, ClientExce
345345
}
346346
else
347347
{
348+
logger.debug( "Network output buffer doesn't need enlarging, flushing data to the channel instead to open up space on the buffer." );
348349
// flush as much data as possible
349350
cipherOut.flip();
350-
if ( channelWrite( cipherOut ) == 0 )
351-
{
352-
throw new ClientException( format(
353-
"Failed to enlarge network buffer from %s to %s. This is either because the " +
354-
"new size is however less than the old size, or because the application " +
355-
"buffer size %s is so big that the application data still cannot fit into the " +
356-
"new network buffer.", curNetSize, netSize, buffer.capacity() ) );
351+
while ( cipherOut.hasRemaining() ) {
352+
int written = channelWrite( cipherOut );
353+
354+
if (written > 0) {
355+
break;
356+
}
357+
358+
logger.debug( "having difficulty flushing data (network contention on local computer?). will continue trying after yielding execution." );
359+
Thread.yield();
360+
361+
logger.debug( "nothing written to the underlying channel (network output buffer is full?), will try till we can." );
357362
}
358363
cipherOut.compact();
359-
logger.debug( "Network output buffer couldn't be enlarged, flushing data to the channel instead." );
360364
}
361365
break;
362366
default:

0 commit comments

Comments
 (0)