Skip to content

Commit c2d0873

Browse files
authored
Merge pull request TooTallNate#1212 from Adeptius/high_cpu_when_channel_close_exception
2 parents 4b75b45 + 11e3d3c commit c2d0873

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

src/main/java/org/java_websocket/SSLSocketChannel2.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -385,10 +385,13 @@ public boolean isConnected() {
385385
public void close() throws IOException {
386386
sslEngine.closeOutbound();
387387
sslEngine.getSession().invalidate();
388-
if (socketChannel.isOpen()) {
389-
socketChannel.write(wrap(emptybuffer));// FIXME what if not all bytes can be written
388+
try {
389+
if (socketChannel.isOpen()) {
390+
socketChannel.write(wrap(emptybuffer));
391+
}
392+
} finally { // in case socketChannel.write produce exception - channel will never close
393+
socketChannel.close();
390394
}
391-
socketChannel.close();
392395
}
393396

394397
private boolean isHandShakeComplete() {

0 commit comments

Comments
 (0)