michielpost / Q42.HueApi

C# helper library to talk to the Philips Hue bridge
MIT License
411 stars 114 forks source link

HttpClient.Timeout of 100 seconds #294

Closed gkapellmann closed 1 year ago

gkapellmann commented 1 year ago

Hello,

I am getting this Exception: image

Basically says: System.Threading.Tasks.TaskCanceledException: 'The request was canceled due to the configured HttpClient.Timeout of 100 seconds elapsing.'

I get tit becuase fo this line: localHueClient.StartEventStream();

If I comment this line, it just doesnt happen. Am I configuring something wrong?

HolgerFreudenreich commented 1 year ago
  var handler = new HttpClientHandler()
  {
    ServerCertificateCustomValidationCallback = HttpClientHandler.DangerousAcceptAnyServerCertificateValidator
  };

  hueHttpClient = new HttpClient(handler);
  hueHttpClient.Timeout = Timeout.InfiniteTimeSpan;

  localHueApi = new LocalHueApi("IP", "KEY", hueHttpClient);
michielpost commented 1 year ago

The answer from @HolgerFreudenreich could help, to set an infinite timeout. But the bridge should send back an answer, so it shouldn't be needed.

Is the IP address correct? Can you do other calls, like: var result = await localHueClient.GetBridgesAsync();

Does that give back a result? If it doesn't, there is something wrong with your ip/key or connection to the bridge.

gkapellmann commented 1 year ago

Thanks for the answer @HolgerFreudenreich

@michielpost The IP is correct, I can actually receive all the events when changing lights, and retrieve the status of the ligths.

The problem appears if I dont do a call of any kind and just leave the program Idle, then after the 100 seconds, it gets fired.

michielpost commented 1 year ago

I was able to reproduce this and just pushed a fix. The StartEventStream method is modified to use it's own HttpClient with an Infinite Timeout. You can optionally pass your own HttpClient if you want to override this behaviour.

Fix is pushed to NuGet in version 0.9.7

gkapellmann commented 1 year ago

Awesome, will test tonight.

gkapellmann commented 1 year ago

Works perfect now, thanks!