io: fix for race conditions in keepalivewriter