Merge pull request #62 from InboxAppCo/fix/mustCallCloseCrash

[Fix] "must call close()" crash
This commit is contained in:
Naoyuki Kanezawa
2016-09-16 14:08:20 +02:00
committed by GitHub

View File

@@ -174,8 +174,13 @@ public class WebSocket extends Transport {
} }
}; };
final int[] total = new int[] { packets.length }; final int[] total = new int[]{packets.length};
for (Packet packet : packets) { for (Packet packet : packets) {
if (this.readyState != ReadyState.OPENING && this.readyState != ReadyState.OPEN) {
// Ensure we don't try to send anymore packets if the socket ends up being closed due to an exception
break;
}
Parser.encodePacket(packet, new Parser.EncodeCallback() { Parser.encodePacket(packet, new Parser.EncodeCallback() {
@Override @Override
public void call(Object packet) { public void call(Object packet) {
@@ -187,6 +192,7 @@ public class WebSocket extends Transport {
} }
} catch (IOException e) { } catch (IOException e) {
logger.fine("websocket closed before onclose event"); logger.fine("websocket closed before onclose event");
close();
} }
if (0 == --total[0]) done.run(); if (0 == --total[0]) done.run();