jens-maus / node-unifi

NodeJS class for querying/controlling a UniFi-Controller (UDM-Pro, UDM-SE, UDM, UDR, UDW, CloudKey Gen1/Gen2) from Ubiquiti (www.ui.com)
MIT License
140 stars 50 forks source link

feat: set timeout for all requests #204

Closed Julusian closed 1 year ago

Julusian commented 1 year ago

When making requests, if the unifi controller is offline or otherwise unreachable the requests would never time out. This could cause an application to get stuck waiting for the request promise to resolve which will never happen, or if the application performs its own timeouts will leak the memory of the in-flight request.

The 5s value has been chosen arbitrarily, as something that feels sensible for something on a local network.

Additionally, I inlined the _connect function, as it was called in one place and the checking of the return value resulted in some dead code

jens-maus commented 1 year ago

Thanks for the contribution. This PR seems reasonable and integrated nicely. Thx.