Skip to content

Websocket is not closed upon missing pong when connection is interrupted #37446

Description

@dspicher

Websockets should be closed with WebSocketStatus.GOING_AWAY if no pong message is received within pingInterval. Why doesn't this work when connectivity is lost, e.g. with an un-plugged cable? Is this expected behaviour?

Reproduce:

  • With a low pingInterval (e.g. 1ms), websocket is correctly closed with closeCode==1001
  • With a high pingInterval (e.g. 1000ms), kill connectivity after a while, websocket will not close (closeCode is null)
import 'dart:async';

import 'package:web_socket_channel/io.dart';

void main() {
  final channel = IOWebSocketChannel.connect("ws://echo.websocket.org/",
      pingInterval: Duration(milliseconds: 1000));
  channel.stream.listen(print, onError: print, onDone: () => print('done'));
  Timer.periodic(Duration(seconds: 3), (t) {
    int time = DateTime.now().millisecondsSinceEpoch;
    channel.sink.add("message: hi, $time");
  });
  Timer.periodic(Duration(seconds: 10), (t) {
    print("close?");
    print(channel.closeCode);
  });
}

  • Dart SDK Version: 2.4.0
  • Linux

Metadata

Metadata

Assignees

Labels

area-core-librarySDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries.library-iotype-bugIncorrect behavior (everything from a crash to more subtle misbehavior)

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions