Fixes #267 Retry write operations on connection failure and master change