[Fix] "must call close()" crash

This commit is contained in:
Stefan Haacker
2016-07-26 11:12:55 -04:00
parent edc8626496
commit 1c166b25d9

View File

@@ -165,6 +165,11 @@ public class WebSocket extends Transport {
final int[] total = new int[]{packets.length};
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() {
@Override
public void call(Object packet) {
@@ -176,6 +181,7 @@ public class WebSocket extends Transport {
}
} catch (IOException e) {
logger.fine("websocket closed before onclose event");
close();
}
if (0 == --total[0]) done.run();