Skip to content
This repository has been archived by the owner on Aug 11, 2020. It is now read-only.

Commit

Permalink
quic: fixup segfault in StatsBase
Browse files Browse the repository at this point in the history
PR-URL: #320
Reviewed-By: Anna Henningsen <anna@addaleax.net>
  • Loading branch information
jasnell committed Feb 4, 2020
1 parent 7ba53ab commit 6951e2d
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 10 deletions.
2 changes: 2 additions & 0 deletions src/quic/node_quic_session.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1372,6 +1372,8 @@ QuicSession::~QuicSession() {
listener_->OnSessionDestroyed();
if (listener_ == listener())
RemoveListener(listener_);

DebugStats();
}

template <typename Fn>
Expand Down
2 changes: 1 addition & 1 deletion src/quic/node_quic_session.h
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ struct QuicSessionStatsTraits {
using Base = QuicSession;

template <typename Fn>
static void ToString(const QuicSession& ptr, Fn&& add_field);
static void ToString(const Base& ptr, Fn&& add_field);
};

class QuicSessionListener {
Expand Down
2 changes: 2 additions & 0 deletions src/quic/node_quic_socket.cc
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,8 @@ QuicSocket::~QuicSocket() {
listener_->OnDestroy();
if (listener == listener_)
RemoveListener(listener_);

DebugStats();
}

template <typename Fn>
Expand Down
2 changes: 1 addition & 1 deletion src/quic/node_quic_socket.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ struct QuicSocketStatsTraits {
using Base = QuicSocket;

template <typename Fn>
static void ToString(const QuicSocket& ptr, Fn&& add_field);
static void ToString(const Base& ptr, Fn&& add_field);
};

class QuicSocket;
Expand Down
4 changes: 3 additions & 1 deletion src/quic/node_quic_stream.cc
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,9 @@ QuicStream::QuicStream(
IncrementStat(&QuicStreamStats::max_offset, params.initial_max_data);
}

QuicStream::~QuicStream() {}
QuicStream::~QuicStream() {
DebugStats();
}

template <typename Fn>
void QuicStreamStatsTraits::ToString(const QuicStream& ptr, Fn&& add_field) {
Expand Down
2 changes: 1 addition & 1 deletion src/quic/node_quic_stream.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ struct QuicStreamStatsTraits {
using Base = QuicStream;

template <typename Fn>
static void ToString(const QuicStream& ptr, Fn&& add_field);
static void ToString(const Base& ptr, Fn&& add_field);
};

// QuicHeader is a base class for implementing QUIC application
Expand Down
8 changes: 3 additions & 5 deletions src/quic/node_quic_util-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -425,11 +425,9 @@ void StatsBase<T>::StatsMemoryInfo(MemoryTracker* tracker) const {
}

template <typename T>
StatsBase<T>::~StatsBase() {
StatsBase<T>::StatsDebug stats_debug(static_cast<typename T::Base*>(this));
Debug(static_cast<typename T::Base*>(this),
"Destroyed. %s",
stats_debug.ToString().c_str());
void StatsBase<T>::DebugStats() {
StatsDebug stats_debug(static_cast<T::Base*>(this));
Debug(static_cast<T::Base*>(this), "Destroyed. %s", stats_debug);
}

template <typename T>
Expand Down
4 changes: 3 additions & 1 deletion src/quic/node_quic_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ class StatsBase {
v8::Local<v8::Object> wrap,
int options = HistogramOptions::NONE);

inline ~StatsBase();
inline ~StatsBase() = default;

// The StatsDebug utility is used when StatsBase is destroyed
// to output statistical information.
Expand Down Expand Up @@ -142,6 +142,8 @@ class StatsBase {

inline void StatsMemoryInfo(MemoryTracker* tracker) const;

inline void DebugStats();

private:
typename T::Stats stats_{};
BaseObjectPtr<HistogramBase> rate_;
Expand Down

0 comments on commit 6951e2d

Please sign in to comment.