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

🐛 RangeError (code): Invalid value: Not in inclusive range 3000..4999: 1000 after updating to 3.0.0 from 2.4.0 #355

Open
tempo-riz opened this issue May 8, 2024 · 6 comments · May be fixed by #370

Comments

@tempo-riz
Copy link

tempo-riz commented May 8, 2024

Hello after upgrading the package from 2.4.0 to 3.0.0 calling close seems to throw (was tested and full working before upgrading) am I missing something ?

For a bit of context the code sends audio data to a server, which returns the transcription
First I start the connection :

  Future<void> start() async {
    _wsChannel = WebSocketChannel.connect(
      buildUrl(_baseLiveUrl, null, queryParams),
      protocols: ['token', apiKey],
    );
    await _wsChannel.ready;

    _wsChannel.stream.listen((event) {
      if (_outputTranscriptStream.isClosed) {
        close();
      } else {
        _outputTranscriptStream.add(...)
      }
    }, onDone: () {
      close();
    }, onError: (error) {
      _outputTranscriptStream.addError(...)
    });

    inputAudioStream.listen((data) {
      if (_wsChannel.closeCode != null) {
        close();
      } else {
        _wsChannel.sink.add(data);
      }
    }, onDone: () {
      close();
    });
  }

The error occurs in the close method :

  Future<void> close() async {
    await _wsChannel.sink.close(status.normalClosure); <------ this throws the following error
    await _outputTranscriptStream.close();
  }

The error :

  RangeError (code): Invalid value: Not in inclusive range 3000..4999: 1000
  dart:core                                                          RangeError.checkValueInInterval
  package:web_socket/src/utils.dart 10:16                            checkCloseCode
  package:web_socket/src/io_web_socket.dart 108:5                    IOWebSocket.close
  package:web_socket_channel/adapter_web_socket_channel.dart 112:27  new AdapterWebSocketChannel.<fn>.<fn>
  package:stream_channel                                             _GuaranteeSink.close
  package:async/src/delegate/stream_sink.dart 47:27                  DelegatingStreamSink.close
  package:web_socket_channel/adapter_web_socket_channel.dart 147:18  _WebSocketSink.close
  package:deepgram_speech_to_text/src/deepgram.dart 68:27            DeepgramLiveTranscriber.close
  package:deepgram_speech_to_text/src/deepgram.dart 62:7             DeepgramLiveTranscriber.start.<fn>
@ekasetiawans
Copy link

+1

@ekasetiawans
Copy link

ekasetiawans commented May 20, 2024

This issue makes our backend leaking connection 😩

@polvallverdu
Copy link

Same issue here when closing the socket. Any updates?

@polvallverdu
Copy link

I investigated a bit, and internally they use code 3001 when the client is told to close the socket, and 3005 when the client closes the connection at their end.

This is not the standard, and should be fixed. Also, the error comes from https://pub.dev/packages/web_socket, so I think this issue should be closed.

@bhumkong
Copy link

bhumkong commented May 29, 2024

Yeah, the issue has been closed in web_socket 0.1.5 – 1000 close code is now allowed.

We should update the docs, because channel.sink.close(status.goingAway) will give this error.

@catapop84
Copy link

I have the some problem. web_socket_channel needs to depend on web_socket 0.1.5 if you want to close with 1000.

@tempo-riz tempo-riz linked a pull request May 29, 2024 that will close this issue
1 task
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants