Skip to content

Commit 62306de

Browse files
committed
Fixed fatal error in buffer management which could cause buffers to be
used more than once at the time resulting in strange protocol errors.
1 parent 8471a35 commit 62306de

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

src/main/java/org/java_websocket/server/WebSocketServer.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,7 @@ public void run() {
325325
ByteBuffer buf = takeBuffer();
326326
try {
327327
if( SocketChannelIOHelper.read( buf, conn, (ByteChannel) conn.channel ) ) {
328+
assert ( buf.hasRemaining() );
328329
conn.inQueue.put( buf );
329330
queue( conn );
330331
i.remove();
@@ -339,9 +340,6 @@ public void run() {
339340
} catch ( IOException e ) {
340341
pushBuffer( buf );
341342
throw e;
342-
} catch ( RuntimeException e ) {
343-
pushBuffer( buf );
344-
throw e;
345343
}
346344
}
347345
if( key.isWritable() ) {
@@ -359,10 +357,12 @@ public void run() {
359357
try {
360358
if( SocketChannelIOHelper.readMore( buf, conn, c ) )
361359
iqueue.add( conn );
360+
assert ( buf.hasRemaining() );
362361
conn.inQueue.put( buf );
363362
queue( conn );
364-
} finally {
363+
} catch ( IOException e ) {
365364
pushBuffer( buf );
365+
throw e;
366366
}
367367

368368
}
@@ -373,7 +373,7 @@ public void run() {
373373
key.cancel();
374374
handleIOException( key, conn, ex );
375375
} catch ( InterruptedException e ) {
376-
return;// FIXME controlled shutdown
376+
return;// FIXME controlled shutdown (e.g. take care of buffermanagement)
377377
}
378378
}
379379

@@ -418,7 +418,7 @@ private void pushBuffer( ByteBuffer buf ) throws InterruptedException {
418418
}
419419

420420
private void handleIOException( SelectionKey key, WebSocket conn, IOException ex ) {
421-
//onWebsocketError( conn, ex );// conn may be null here
421+
// onWebsocketError( conn, ex );// conn may be null here
422422
if( conn != null ) {
423423
conn.closeConnection( CloseFrame.ABNORMAL_CLOSE, ex.getMessage() );
424424
} else if( key != null ) {

0 commit comments

Comments
 (0)