You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficserver.apache.org by ma...@apache.org on 2018/04/01 08:24:20 UTC
[trafficserver] branch quic-latest updated: add refcount to protect
qvc
This is an automated email from the ASF dual-hosted git repository.
masaori pushed a commit to branch quic-latest
in repository https://gitbox.apache.org/repos/asf/trafficserver.git
The following commit(s) were added to refs/heads/quic-latest by this push:
new cef7119 add refcount to protect qvc
cef7119 is described below
commit cef711994b9b676f1713bf4e79419d8f1c3a40fc
Author: scw00 <sc...@apache.org>
AuthorDate: Tue Feb 20 11:26:38 2018 +0800
add refcount to protect qvc
---
iocore/net/P_QUICNetVConnection.h | 3 ++-
iocore/net/QUICClosedConCollector.cc | 5 +++--
iocore/net/QUICNet.cc | 26 +++++++++++++++++++++--
iocore/net/QUICNetVConnection.cc | 41 ++++++++++++++++++++++++------------
4 files changed, 56 insertions(+), 19 deletions(-)
diff --git a/iocore/net/P_QUICNetVConnection.h b/iocore/net/P_QUICNetVConnection.h
index e0baec5..6b34210 100644
--- a/iocore/net/P_QUICNetVConnection.h
+++ b/iocore/net/P_QUICNetVConnection.h
@@ -142,7 +142,7 @@ class SSLNextProtocolSet;
* WRITE:
* Do nothing
**/
-class QUICNetVConnection : public UnixNetVConnection, public QUICConnection
+class QUICNetVConnection : public UnixNetVConnection, public QUICConnection, public RefCountObj
{
using super = UnixNetVConnection; ///< Parent type.
@@ -168,6 +168,7 @@ public:
int state_connection_draining(int event, Event *data);
int state_connection_closed(int event, Event *data);
void start();
+ void remove_connection_ids();
void free(EThread *t) override;
void destroy(EThread *t);
diff --git a/iocore/net/QUICClosedConCollector.cc b/iocore/net/QUICClosedConCollector.cc
index 19095fe..647468e 100644
--- a/iocore/net/QUICClosedConCollector.cc
+++ b/iocore/net/QUICClosedConCollector.cc
@@ -43,7 +43,7 @@ QUICClosedConCollector::_process_closed_connection(EThread *t)
while ((qvc = this->_localClosedQueue.pop())) {
if (qvc->shouldDestroy()) {
- qvc->free(t);
+ qvc->destroy(t);
} else {
local_queue.push(qvc);
}
@@ -51,8 +51,9 @@ QUICClosedConCollector::_process_closed_connection(EThread *t)
SList(QUICNetVConnection, closed_alink) aq(this->closedQueue.popall());
while ((qvc = aq.pop())) {
+ qvc->remove_connection_ids();
if (qvc->shouldDestroy()) {
- qvc->free(t);
+ qvc->destroy(t);
} else {
local_queue.push(qvc);
}
diff --git a/iocore/net/QUICNet.cc b/iocore/net/QUICNet.cc
index f73ba26..f51c5ac 100644
--- a/iocore/net/QUICNet.cc
+++ b/iocore/net/QUICNet.cc
@@ -31,11 +31,19 @@ QUICPollEvent::init(QUICConnection *con, UDPPacketInternal *packet)
{
this->con = con;
this->packet = packet;
+ if (con != nullptr) {
+ static_cast<QUICNetVConnection *>(con)->refcount_inc();
+ }
}
void
QUICPollEvent::free()
{
+ if (this->con != nullptr) {
+ ink_assert(static_cast<QUICNetVConnection *>(this->con)->refcount_dec() >= 0);
+ this->con = nullptr;
+ }
+
quicPollEventAllocator.free(this);
}
@@ -61,9 +69,9 @@ QUICPollCont::_process_long_header_packet(QUICPollEvent *e, NetHandler *nh)
QUICNetVConnection *vc = static_cast<QUICNetVConnection *>(e->con);
uint8_t *buf = (uint8_t *)p->getIOBlockChain()->buf();
- e->free();
if (!QUICTypeUtil::has_connection_id(reinterpret_cast<const uint8_t *>(buf))) {
// TODO: Some packets may not have connection id
+ e->free();
p->free();
return;
}
@@ -73,6 +81,7 @@ QUICPollCont::_process_long_header_packet(QUICPollEvent *e, NetHandler *nh)
vc->read.triggered = 1;
vc->handle_received_packet(p);
vc->handleEvent(QUIC_EVENT_PACKET_READ_READY, nullptr);
+ e->free();
return;
}
@@ -90,6 +99,9 @@ QUICPollCont::_process_long_header_packet(QUICPollEvent *e, NetHandler *nh)
nh->read_enable_list.push(vc);
}
}
+
+ // Note: We should free QUICPollEvent here since vc could be freed from other thread.
+ e->free();
}
void
@@ -100,10 +112,10 @@ QUICPollCont::_process_short_header_packet(QUICPollEvent *e, NetHandler *nh)
QUICNetVConnection *vc = static_cast<QUICNetVConnection *>(e->con);
buf = (uint8_t *)p->getIOBlockChain()->buf();
- e->free();
if (!QUICTypeUtil::has_connection_id(reinterpret_cast<const uint8_t *>(buf))) {
// TODO: Some packets may not have connection id
p->free();
+ e->free();
return;
}
@@ -115,6 +127,9 @@ QUICPollCont::_process_short_header_packet(QUICPollEvent *e, NetHandler *nh)
if (!isin) {
nh->read_enable_list.push(vc);
}
+
+ // Note: We should free QUICPollEvent here since vc could be freed from other thread.
+ e->free();
}
//
@@ -134,6 +149,13 @@ QUICPollCont::pollEvent(int, Event *)
SList(QUICPollEvent, alink) aq(inQueue.popall());
Queue<QUICPollEvent> result;
while ((e = aq.pop())) {
+ QUICNetVConnection *qvc = static_cast<QUICNetVConnection *>(e->con);
+ UDPPacketInternal *p = e->packet;
+ if (qvc != nullptr && qvc->in_closed_queue) {
+ p->free();
+ e->free();
+ continue;
+ }
result.push(e);
}
diff --git a/iocore/net/QUICNetVConnection.cc b/iocore/net/QUICNetVConnection.cc
index 96c1e06..759b454 100644
--- a/iocore/net/QUICNetVConnection.cc
+++ b/iocore/net/QUICNetVConnection.cc
@@ -87,8 +87,7 @@ QUICNetVConnection::init(QUICConnectionId original_cid, UDPConnection *udp_con,
bool
QUICNetVConnection::shouldDestroy()
{
- // TODO: return this->refcount == 0;
- return true;
+ return this->refcount() == 0;
}
VIO *
@@ -212,16 +211,12 @@ void
QUICNetVConnection::free(EThread *t)
{
QUICConDebug("Free connection");
-
- this->_ctable->erase(this->_original_quic_connection_id, this);
- this->_ctable->erase(this->_quic_connection_id, this);
- if (this->_alt_con_manager) {
- this->_alt_con_manager->invalidate_alt_connections();
- }
+ this->remove_connection_ids();
/* TODO: Uncmment these blocks after refactoring read / write process
this->_udp_con = nullptr;
this->_packet_handler = nullptr;
+
_unschedule_packet_write_ready();
delete this->_handshake_handler;
@@ -235,9 +230,28 @@ QUICNetVConnection::free(EThread *t)
delete this->_alt_con_manager;
}
- // TODO: clear member variables like `UnixNetVConnection::free(EThread *t)`
- this->mutex.clear();
+ super::clear();
+ */
+ this->_packet_handler->close_conenction(this);
+}
+
+// called by ET_UDP
+void
+QUICNetVConnection::remove_connection_ids()
+{
+ this->_ctable->erase(this->_original_quic_connection_id, this);
+ this->_ctable->erase(this->_quic_connection_id, this);
+ if (this->_alt_con_manager) {
+ this->_alt_con_manager->invalidate_alt_connections();
+ }
+}
+// called by ET_UDP
+void
+QUICNetVConnection::destroy(EThread *t)
+{
+ QUICConDebug("Destroy connection");
+ /* TODO: Uncmment these blocks after refactoring read / write process
if (from_accept_thread) {
quicNetVCAllocator.free(this);
} else {
@@ -660,11 +674,10 @@ QUICNetVConnection::state_connection_closed(int event, Event *data)
this->_loss_detector->handleEvent(QUIC_EVENT_LD_SHUTDOWN, nullptr);
if (this->nh) {
- this->nh->stopCop(this);
- this->nh->stopIO(this);
+ this->nh->free_netvc(this);
+ } else {
+ this->free(this->mutex->thread_holding);
}
-
- this->_packet_handler->close_conenction(this);
break;
}
case QUIC_EVENT_PACKET_WRITE_READY: {
--
To stop receiving notification emails like this one, please contact
masaori@apache.org.