Rework keep-alive throttling logic to avoid data race.

Fix race condition #51