- // If no further flush is needed, than we fail all unflushed segments, so that each enqueued entry
- // is reported as unsuccessful due to channel disconnection. No further entries should be enqueued
- // by this time.
- needsFlush = needsFlush();
+ // If no further flush is needed or we are not able to write to channel anymore, then we fail all unflushed
+ // segments, so that each enqueued entry is reported as unsuccessful due to channel disconnection.
+ // No further entries should be enqueued by this time.
+ needsFlush = channel.isWritable() && needsFlush();