Index: sdk/lib/io/websocket_impl.dart |
diff --git a/sdk/lib/io/websocket_impl.dart b/sdk/lib/io/websocket_impl.dart |
index 6e308094aabceb22ef8580c0e658a8cecdc649c4..5c887cf2aa279e210b79fa038fb907f0785b3f0d 100644 |
--- a/sdk/lib/io/websocket_impl.dart |
+++ b/sdk/lib/io/websocket_impl.dart |
@@ -959,16 +959,26 @@ class _WebSocketImpl extends Stream with _ServiceObject implements WebSocket { |
_outCloseCode = code; |
_outCloseReason = reason; |
} |
- if (_closeTimer == null && !_controller.isClosed) { |
- // When closing the web-socket, we no longer accept data. |
- _closeTimer = new Timer(const Duration(seconds: 5), () { |
- // Reuse code and reason from the local close. |
- _closeCode = _outCloseCode; |
- _closeReason = _outCloseReason; |
- _subscription.cancel(); |
- _controller.close(); |
- _webSockets.remove(_serviceId); |
- }); |
+ if (!_controller.isClosed) { |
+ // If a close has not yet been received from the other end then |
+ // 1) make sure to listen on the stream so the close frame will be |
+ // processed if received. |
+ // 2) set a timer terminate the connection if a close frame is |
+ // not received. |
+ if (!_controller.hasListener) { |
+ _controller.stream.drain(); |
kustermann
2015/05/08 13:21:20
This can cause an un-catchable exception. You need
Søren Gjesse
2015/06/15 07:51:32
Thanks. Added catchError which ignored the error.
|
+ } |
+ if (_closeTimer == null) { |
+ // When closing the web-socket, we no longer accept data. |
+ _closeTimer = new Timer(const Duration(seconds: 5), () { |
+ // Reuse code and reason from the local close. |
+ _closeCode = _outCloseCode; |
+ _closeReason = _outCloseReason; |
+ _subscription.cancel(); |
+ _controller.close(); |
+ _webSockets.remove(_serviceId); |
+ }); |
+ } |
} |
return _sink.close(); |
} |