patch 7.4.1807
Problem:    Test_out_close_cb sometimes fails.
Solution:   Always write DETACH to out, not err.
diff --git a/src/channel.c b/src/channel.c
index 1be3d27..aa58803 100644
--- a/src/channel.c
+++ b/src/channel.c
@@ -2478,6 +2478,7 @@
 	   * first invoke the close callback.  Increment the refcount to avoid
 	   * the channel being freed halfway. */
 	  ++channel->ch_refcount;
+	  ch_log(channel, "Invoking callbacks before closing");
 	  for (part = PART_SOCK; part <= PART_ERR; ++part)
 	      while (may_invoke_callback(channel, part))
 		  ;
@@ -2783,7 +2784,7 @@
      */
     if (channel->ch_part[part].ch_mode == MODE_RAW
 			     || channel->ch_part[part].ch_mode == MODE_NL)
-	channel_save(channel, part, (char_u *)DETACH_MSG_RAW,
+	channel_save(channel, PART_OUT, (char_u *)DETACH_MSG_RAW,
 			      (int)STRLEN(DETACH_MSG_RAW), FALSE, "PUT ");
 
     /* When reading from stdout is not possible, assume the other side has