Both `write` and `close` can fail.