Skip to content

Commit f0ef4df

Browse files
committed
quick fix for deadlock TooTallNate#61 / TooTallNate#75
1 parent 020b066 commit f0ef4df

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

src/org/java_websocket/WebSocket.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -544,12 +544,22 @@ public void startHandshake( ClientHandshakeBuilder handshakedata ) throws Invali
544544
private void channelWrite( ByteBuffer buf ) throws InterruptedException {
545545
if( DEBUG )
546546
System.out.println( "write(" + buf.limit() + "): {" + ( buf.limit() > 1000 ? "too big to display" : new String( buf.array() ) ) + "}" );
547-
buf.rewind();
547+
buf.rewind(); // TODO rewinding should not be nessesary
548548
synchronized (bufferQueueTotalAmount) {
549549
// add up the number of bytes to the total queued (synchronized over this object)
550550
bufferQueueTotalAmount += buf.limit();
551551
}
552-
bufferQueue.put( buf );
552+
if( !bufferQueue.offer( buf ) ) {
553+
try {
554+
flush();
555+
} catch ( IOException e ) {
556+
wsl.onWebsocketError( this, e );
557+
closeConnection( CloseFrame.ABNROMAL_CLOSE, true );
558+
return;
559+
}
560+
bufferQueue.put( buf );
561+
}
562+
553563
wsl.onWriteDemand( this );
554564
}
555565

0 commit comments

Comments
 (0)