Skip to content

Websocket connection/reconnection cpu spike #318

@1-leo

Description

@1-leo

Describe the bug
Ndk takes really long for the first request with very high cpu usage

the problem is caused by

    _stateStreamSubscription = _websocketDS.ws.connection.listen((state) {
      Logger.log.t("${_websocketDS.url} connection state changed to $state");
      if (state is Connected || state is Reconnected) {
        if (!completer.isCompleted) {
          completer.complete();
        }
        if (state is Reconnected && onReconnect != null) {
          onReconnect.call();
        }
      } else if (state is Disconnected) {
        completer = Completer();
        ready = completer.future;
      } else if (state is Connecting || state is Reconnecting) {
        // Do nothing, just waiting for (re)connection to be established
      } else {
        Logger.log.w(
            "${_websocketDS.url} connection state changed to unknown state: $state");
      }
    });

Because a callback is called the issue might be upstream.
Commenting this code resolves the issue but breaks future requests

I suspect a loop when relay is in connecting/reconnecting state causing the cpu spike

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinghelp wantedExtra attention is needed

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions