Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(960)

Unified Diff: sdk/lib/io/websocket_impl.dart

Issue 1133673006: Make sure to process WebSocket frames when closing a WebSocket (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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();
}
« no previous file with comments | « no previous file | tests/standalone/io/web_socket_pipe_test.dart » ('j') | tests/standalone/io/web_socket_test.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698