Make sure writing to a closed channel does not trigger an UnsupportedOperationException

- Fixes #1442