crimson/net: fix potential parallel write in SocketConnection 25939/head
authorYingxin Cheng <yingxincheng@gmail.com>
Mon, 14 Jan 2019 02:43:05 +0000 (10:43 +0800)
committerYingxin Cheng <yingxincheng@gmail.com>
Tue, 15 Jan 2019 05:17:48 +0000 (13:17 +0800)
All the write/flush in SocketConnection should be serialized, or nasty
segment-fault could happen in seastar which is hard to diagnose.

This fix serializes the writes in `handle_keepalive2()` with other
writes in the open state.

Signed-off-by: Yingxin Cheng <yingxincheng@gmail.com>
src/crimson/net/SocketConnection.cc

index 0d3d1181fa0950dfdf870a9079e9c186d1bed5a3..745348f91f2f4f50757fd207e7bbc98bbdf34ca8 100644 (file)
@@ -551,8 +551,12 @@ SocketConnection::handle_keepalive2()
   return socket->read_exactly(sizeof(ceph_timespec))
     .then([this] (auto buf) {
       k.ack.stamp = *reinterpret_cast<const ceph_timespec*>(buf.get());
-      logger().info("{} keepalive2 {}", *this, k.ack.stamp.tv_sec);
-      return socket->write_flush(make_static_packet(k.ack));
+      seastar::shared_future<> f = send_ready.then([this] {
+          logger().info("{} keepalive2 {}", *this, k.ack.stamp.tv_sec);
+          return socket->write_flush(make_static_packet(k.ack));
+        });
+      send_ready = f.get_future();
+      return f.get_future();
     });
 }