Bouke / HAP

Swift implementation of the Homekit Accessory Protocol
https://boukehaarsma.nl/HAP/
MIT License
366 stars 50 forks source link

Fix thread safety in pairing endpoints and ChannelHandlers #88

Closed gbrooker closed 5 years ago

gbrooker commented 5 years ago

I've been seeing hard crashes due to unsafe access to shared dictionaries from multiple NIO threads in these functions. I've added code to ensure all accesses are thread-safe. The sessions array may be read concurrently, but writes are exclusive.

Regarding the TODO comment on not freeing memory you wrote, should we setup a timeout to clear sessions if the pairing does not complete, or a background process to flush out old sessions once per hour ?

Bouke commented 5 years ago

Thanks for the fix!

Regarding the TODO comment on not freeing memory you wrote, should we setup a timeout to clear sessions if the pairing does not complete, or a background process to flush out old sessions once per hour ?

Any setup is fine I guess; where the timeout would probably be the overall lower on resources as there won't be unneeded background cleanup going on.