Aldaviva/Kasa

TcpMutex prevents concurrent requests

Closed this issue · 4 comments

nzbart commented

When querying multiple devices, some of which may time out, the requests don't happen in parallel. When querying, say 10 devices, this means the total time could be around 300 seconds instead of 30 seconds. This appears to be because there is a global process-wide lock called TcpMutex:

private static readonly SemaphoreSlim TcpMutex = new(1);

The TcpClient itself is one-per-instance:

private TcpClient _tcpClient;

Would it be possible to reduce the scope of TcpMutex to per-instance rather than per process?

Oops that's a great point. I forgot that field was static. Thanks, I will work on this.

Should be fixed, feel free to give this a try and let me know if it works for you.

Kasa.nupkg.zip (from build 25)

nzbart commented

@Aldaviva thanks for getting onto this so quickly! I've tested version 1.0.1, and the fix appears to work as expected.

You're welcome!

Published to NuGet Gallery as version 1.0.1.