Fix possible IOError due to second write() call in _copy_data().

 * Fixes #1931.
Merge branch 'fix/1921-1927-1929-hanging-fds' into development