Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Faye: Invalid websocket close code used for Web #244

Open
1 of 6 tasks
dehalui opened this issue Jan 26, 2023 · 0 comments
Open
1 of 6 tasks

Faye: Invalid websocket close code used for Web #244

dehalui opened this issue Jan 26, 2023 · 0 comments
Labels
bug Something isn't working

Comments

@dehalui
Copy link

dehalui commented Jan 26, 2023

Describe the bug
The FayeClient uses code 1001 when closing the web socket channel

image

This results in the exception below when running on Flutter Web. Error is reproduced in browsers Chrome, Edge, Firefox, and Safari.

html.dart:132 Uncaught (in promise) DOMException: Failed to execute 'close' on 'WebSocket': The code must be either 1000, or between 3000 and 4999. 1001 is neither.
    at http://localhost:59770/packages/web_socket_channel/src/copy/web_socket_impl.dart.lib.js:1356:33
    at _RootZone.runGuarded (http://localhost:59770/dart_sdk.js:40331:11)
    at sendDone (http://localhost:59770/dart_sdk.js:34212:24)
    at [_sendDone] (http://localhost:59770/dart_sdk.js:34222:11)
    at [_close] (http://localhost:59770/dart_sdk.js:34138:26)
    at [_sendDone] (http://localhost:59770/dart_sdk.js:37129:36)
    at [_sendDone] (http://localhost:59770/dart_sdk.js:37239:32)
    at [_closeUnchecked] (http://localhost:59770/dart_sdk.js:36928:26)
    at _SyncStreamController.new.close (http://localhost:59770/dart_sdk.js:36922:30)
    at http://localhost:59770/packages/stream_channel/src/stream_channel_controller.dart.lib.js:1114:39
    at _RootZone.runGuarded (http://localhost:59770/dart_sdk.js:40331:11)
    at sendDone (http://localhost:59770/dart_sdk.js:34212:24)
    at [_sendDone] (http://localhost:59770/dart_sdk.js:34222:11)
    at [_close] (http://localhost:59770/dart_sdk.js:34138:26)
    at [_sendDone] (http://localhost:59770/dart_sdk.js:37129:36)
    at [_sendDone] (http://localhost:59770/dart_sdk.js:37239:32)
    at [_closeUnchecked] (http://localhost:59770/dart_sdk.js:36928:26)
    at _SyncStreamController.new.close (http://localhost:59770/dart_sdk.js:36922:30)
    at _StreamSinkWrapper.new.close (http://localhost:59770/dart_sdk.js:37276:31)
    at _GuaranteeSink.new.close (http://localhost:59770/packages/stream_channel/src/stream_channel_controller.dart.lib.js:1223:56)
    at html$._HtmlWebSocketSink.new.close (http://localhost:59770/packages/async/src/delegate/stream_sink.dart.lib.js:43:29)
    at html$._HtmlWebSocketSink.new.close (http://localhost:59770/packages/web_socket_channel/src/copy/web_socket_impl.dart.lib.js:1457:20)
    at [_closeWebSocketChannel] (http://localhost:59770/packages/faye_dart/src/subscription.dart.lib.js:496:39)
    at http://localhost:59770/packages/faye_dart/src/subscription.dart.lib.js:589:43
    at http://localhost:59770/packages/faye_dart/src/subscription.dart.lib.js:695:30
    at client.FayeClient.new.pipeThroughExtensions (http://localhost:59770/packages/faye_dart/src/extensible.dart.lib.js:46:47)
    at [_receiveMessage] (http://localhost:59770/packages/faye_dart/src/subscription.dart.lib.js:689:12)
    at [_onDataReceived] (http://localhost:59770/packages/faye_dart/src/subscription.dart.lib.js:528:30)
    at _RootZone.runUnaryGuarded (http://localhost:59770/dart_sdk.js:40347:11)
    at [_sendData] (http://localhost:59770/dart_sdk.js:34170:22)
    at [_add] (http://localhost:59770/dart_sdk.js:34120:26)
    at [_sendData] (http://localhost:59770/dart_sdk.js:37123:34)
    at [_sendData] (http://localhost:59770/dart_sdk.js:37233:32)
    at [_add] (http://localhost:59770/dart_sdk.js:36936:26)
    at _SyncStreamController.new.add (http://localhost:59770/dart_sdk.js:36903:19)
    at _RootZone.runUnaryGuarded (http://localhost:59770/dart_sdk.js:40347:11)
    at [_sendData] (http://localhost:59770/dart_sdk.js:34170:22)
    at [_add] (http://localhost:59770/dart_sdk.js:34120:26)
    at [_sendData] (http://localhost:59770/dart_sdk.js:37123:34)
    at [_sendData] (http://localhost:59770/dart_sdk.js:37233:32)
    at [_add] (http://localhost:59770/dart_sdk.js:36936:26)
    at _SyncStreamController.new.add (http://localhost:59770/dart_sdk.js:36903:19)
    at _StreamSinkWrapper.new.add (http://localhost:59770/dart_sdk.js:37270:24)
    at _GuaranteeSink.new.add (http://localhost:59770/packages/stream_channel/src/stream_channel_controller.dart.lib.js:1180:24)
    at http://localhost:59770/packages/web_socket_channel/src/copy/web_socket_impl.dart.lib.js:1406:37
    at Object._checkAndCall (http://localhost:59770/dart_sdk.js:5438:16)
    at Object.dcall (http://localhost:59770/dart_sdk.js:5443:17)
    at WebSocket.<anonymous> (http://localhost:59770/dart_sdk.js:109088:100)

The description matches the valid values in the WebSocket.close web api documentation here

Please make the close code configurable or use one in the valid range for web that is also compatible with the other platforms

What version of Flutter do you use?
Flutter version 3.3.3

What package are you using? What version?
package: faye_dart
version: 0.1.1+2

What platform is it about?

  • Android
  • iOS
  • Web
  • Windows
  • MacOS
  • Linux
    ls

a copy of flutter doctor --verbose

$ flutter doctor --verbose
[✓] Flutter (Channel stable, 3.3.3, on macOS 12.6.1 21G217 darwin-x64, locale en-US)
    • Flutter version 3.3.3 on channel stable at <redacted>/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 18a827f393 (4 months ago), 2022-09-28 10:03:14 -0700
    • Engine revision 5c984c26eb
    • Dart version 2.18.2
    • DevTools version 2.15.0

[✓] Android toolchain - develop for Android devices (Android SDK version 31.0.0)
    • Android SDK at <redacted>/Android/sdk
    • Platform android-33, build-tools 31.0.0
    • Java binary at: /Applications/Android Studio.app/Contents/jre/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 11.0.10+0-b96-7281165)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 14.1)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 14B47b
    • CocoaPods version 1.11.2

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2020.3)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 11.0.10+0-b96-7281165)

[✓] IntelliJ IDEA Community Edition (version 2021.2.2)
    • IntelliJ at /Applications/IntelliJ IDEA CE.app
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart

[✓] VS Code (version 1.74.2)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.58.0

[✓] Connected device (3 available)
    • macOS (desktop)   • macos       • darwin-x64     • macOS 12.6.1 21G217 darwin-x64
    • Chrome (web)      • chrome      • web-javascript • Google Chrome 109.0.5414.119

[✓] HTTP Host Availability
    • All required HTTP hosts are available

• No issues found!

To Reproduce
Steps to reproduce the behavior:

  1. Add sample app
class MyHomePage extends StatefulWidget {
  const MyHomePage({Key? key, required this.title}) : super(key: key);

  final String title;

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  FayeClient? client;

  List<Subscription> subscriptions = [];

  final serverTextController = TextEditingController();

  @override
  void initState() {
    super.initState();
  }

  @override
  void dispose() {
    super.dispose();
    serverTextController.dispose();
  }

  void connect() {
    if (client == null) {
      client = FayeClient(serverTextController.text);

      client?.connect();
    }
  }

  Future<void> disconnect() async {
    try {
      await client?.disconnect();
    } finally {
      client = null;
    }
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(widget.title),
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            Row(
              mainAxisAlignment: MainAxisAlignment.center,
              children: [
                SizedBox(
                    width: 400,
                    child: TextField(
                      controller: serverTextController,
                      decoration: const InputDecoration(
                        hintText: 'wss://ws.server.com/faye',
                        border: OutlineInputBorder(),
                        labelText: 'Faye Server',
                      ),
                    )),
                const SizedBox(
                  width: 20,
                ),
                ElevatedButton(
                    onPressed: () async {
                      connect();
                    },
                    child: const Text('Connect')),
              ],
            ),
            const SizedBox(
              height: 40,
            ),
            ElevatedButton(
                onPressed: () async {
                  await disconnect();
                },
                child: const Text('Disconnect')),
          ],
        ),
      ),
    );
  }
}
  1. Connect to faye server
  2. Disconnect
  3. Observe error in browser console

Expected behavior
Client disconnects without exception

Screenshots
see above

Logs
Run flutter analyze and attach any output of that command below.
If there are any analysis errors, try resolving them before filing this issue.

 flutter analyze
Analyzing example...                                                    
No issues found! (ran in 2.6s)

Additional context
none

@dehalui dehalui added the bug Something isn't working label Jan 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant