signalr_client
signalr_client copied to clipboard
Failed to complete negotiation with the server: TimeoutException after 0:00:02.000000: Future not completed Dart
Hi, thanks you for such great package.
I am struggiling with this error - SEVERE: 2022-08-16 16:01:01.915620: Failed to complete negotiation with the server: TimeoutException after 0:00:02.000000: Future not completed
If there any chance to prevent it? I get a big pile of data and I don't want my websocket connection to fail and I need to wait until it is all done. As I understand it is not a backend issue (or may be I am wrong, I have searched a lot about this problem but any solutions dosen't work in my case).
My code is like that:
Future<List> fetchAllBugStuff() async {
Logger.root.level = Level.ALL;
Logger.root.onRecord.listen((LogRecord rec) {
print('${rec.level.name}: ${rec.time}: ${rec.message}');
});
final transportProtLogger = Logger("SignalR - transport");
Logger? logger;
final httpConnectionOptions = HttpConnectionOptions(
accessTokenFactory: () => SharedPreferenceService().loginWithToken(),
headers: defaultHeaders,
logger: transportProtLogger,
logMessageContent: true,
);
final hubConnection = HubConnectionBuilder()
.withUrl(
'http://10.10/home',
options: httpConnectionOptions,
)
.build();
await hubConnection.start();
List fixation = [];
if (hubConnection.state == HubConnectionState.Connected) {
await hubConnection
.invoke('GetAllBigStuff')
.then((value) => fixation = value as List);
}
hubConnection.keepAliveIntervalInMilliseconds = 10 * 60 * 60 * 1000;
hubConnection.onclose(({error}) {
Logger.root.level = Level.SHOUT;
Logger.root.onRecord.listen((LogRecord rec) {
print('${rec.level.name}: ${rec.error}: ${rec.message}');
});
logger?.finer(error);
});
// print(fixation);
return fixation;
}
Thanks you for your replying :)
It's not an Issue. Just change requestTimeout
inside HubConnectionBuilder
.
Common problem is race condition, especially on flutter hotReload. Check that start is not called twice at the same time. For example, if your code is based on 'chatPageViewModel.dart' just remove openConnection
from model constructor: