From 11fa71c14b053df19384beb37ad16012e4de5591 Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Sat, 15 Jun 2019 14:41:25 +0900 Subject: [PATCH] h2load: Fix possible deadlock --- src/h2load_quic.cc | 32 +++++++++++++++++++++++++++++--- 1 file changed, 29 insertions(+), 3 deletions(-) diff --git a/src/h2load_quic.cc b/src/h2load_quic.cc index a8158400..fe5c6b80 100644 --- a/src/h2load_quic.cc +++ b/src/h2load_quic.cc @@ -962,20 +962,46 @@ int Client::write_quic() { return -1; } - auto s = static_cast(session.get()); - std::array vec; std::array buf; ngtcp2_path_storage ps; ngtcp2_path_storage_zero(&ps); + if (!session) { + auto nwrite = + ngtcp2_conn_write_pkt(quic.conn, &ps.path, buf.data(), quic.max_pktlen, + timestamp(worker->loop)); + if (nwrite < 0) { + quic.last_error = quic::err_transport(nwrite); + return -1; + } + + quic_restart_pkt_timer(); + + if (nwrite) { + write_udp(reinterpret_cast(ps.path.remote.addr), + ps.path.remote.addrlen, buf.data(), nwrite); + + ev_io_start(worker->loop, &wev); + return 0; + } + + // session might be initialized during ngtcp2_conn_write_pkt. + if (!session) { + ev_io_stop(worker->loop, &wev); + return 0; + } + } + + auto s = static_cast(session.get()); + for (;;) { int64_t stream_id; int fin; ssize_t sveccnt = 0; - if (s && ngtcp2_conn_get_max_data_left(quic.conn)) { + if (ngtcp2_conn_get_max_data_left(quic.conn)) { sveccnt = s->write_stream(stream_id, fin, vec.data(), vec.size()); if (sveccnt == -1) { return -1;