mirror of
https://github.com/ruby/ruby.git
synced 2026-10-29 00:46:26 +08:00
When a socket has buffered output (`sync == false`) and `#close_write` is called, the write side was shut down via `shutdown(SHUT_WR)` without first flushing the buffer. This had two bad consequences: - the buffered bytes were silently dropped (never delivered to the peer); - a subsequent `#close` tried to flush the still-populated write buffer into the now `shutdown(SHUT_WR)` socket and raised `Errno::EPIPE`. Flush the buffer before shutting down the write side, matching the write-only branch (which flushes via `rb_io_close`) and the non-socket `IO#close_write` path. `IO#close_write` for a plain `IO` wrapping a socket fd is fixed in the same way. Assisted-By: devx/2c064143-8655-4631-a7cd-6395bb241bdc