BIND 10 master, updated. 50f16fdb5e03054e470dca9aba6408062c198fd7 [master] update ChangeLog for trac957
BIND 10 source code commits
bind10-changes at lists.isc.org
Mon Jun 13 04:49:07 UTC 2011
The branch, master has been updated
via 50f16fdb5e03054e470dca9aba6408062c198fd7 (commit)
via e59c215e14b5718f62699ec32514453b983ff603 (commit)
via 49ae23f163b8e4ad45f7146f95235253691a0f4b (commit)
via 1ff545f50926224d095e3809636c642219ea9078 (commit)
via e47b0a39b7849489e6d9a167117ebb3be5eea4d4 (commit)
via 3e1fae0b23d4df32f239e5aa1350e40557d8ada4 (commit)
from 6c92dafaffbb0c1ff83ffc8a1004cc40cd500310 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commit 50f16fdb5e03054e470dca9aba6408062c198fd7
Author: Yoshitaka Aharen <aharen at jprs.co.jp>
Date: Mon Jun 13 13:47:56 2011 +0900
[master] update ChangeLog for trac957
-----------------------------------------------------------------------
Summary of changes:
ChangeLog | 6 +++
src/lib/asiolink/interval_timer.cc | 63 ++++++++++++++++++++++-------------
src/lib/asiolink/interval_timer.h | 10 ++---
3 files changed, 49 insertions(+), 30 deletions(-)
-----------------------------------------------------------------------
diff --git a/ChangeLog b/ChangeLog
index 725a0a6..0a48516 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+257. [bug] y-aharen
+ Fixed a bug an instance of IntervalTimerImpl may be destructed
+ while deadline_timer is holding the handler. This fix addresses
+ occasional failure of IntervalTimerTest.destructIntervalTimer.
+ (Trac #957, git e59c215e14b5718f62699ec32514453b983ff603)
+
256. [bug] jerry
src/bin/xfrin: update xfrin to check TSIG before other part of
incoming message.
diff --git a/src/lib/asiolink/interval_timer.cc b/src/lib/asiolink/interval_timer.cc
index 0ed06eb..9873e9b 100644
--- a/src/lib/asiolink/interval_timer.cc
+++ b/src/lib/asiolink/interval_timer.cc
@@ -14,11 +14,9 @@
#include <config.h>
-#include <unistd.h> // for some IPC/network system calls
-#include <sys/socket.h>
-#include <netinet/in.h>
-
#include <boost/bind.hpp>
+#include <boost/enable_shared_from_this.hpp>
+#include <boost/shared_ptr.hpp>
#include <exceptions/exceptions.h>
@@ -29,7 +27,16 @@
namespace isc {
namespace asiolink {
-class IntervalTimerImpl {
+/// This class holds a call back function of asynchronous operations.
+/// To ensure the object is alive while an asynchronous operation refers
+/// to it, we use shared_ptr and enable_shared_from_this.
+/// The object will be destructed in case IntervalTimer has been destructed
+/// and no asynchronous operation refers to it.
+/// Please follow the link to get an example:
+/// http://think-async.com/asio/asio-1.4.8/doc/asio/tutorial/tutdaytime3.html#asio.tutorial.tutdaytime3.the_tcp_connection_class
+class IntervalTimerImpl :
+ public boost::enable_shared_from_this<IntervalTimerImpl>
+{
private:
// prohibit copy
IntervalTimerImpl(const IntervalTimerImpl& source);
@@ -53,14 +60,18 @@ private:
long interval_;
// asio timer
asio::deadline_timer timer_;
+ // interval_ will be set to this value in destructor in order to detect
+ // use-after-free type of bugs.
+ static const long INVALIDATED_INTERVAL = -1;
};
IntervalTimerImpl::IntervalTimerImpl(IOService& io_service) :
interval_(0), timer_(io_service.get_io_service())
{}
-IntervalTimerImpl::~IntervalTimerImpl()
-{}
+IntervalTimerImpl::~IntervalTimerImpl() {
+ interval_ = INVALIDATED_INTERVAL;
+}
void
IntervalTimerImpl::setup(const IntervalTimer::Callback& cbfunc,
@@ -81,42 +92,46 @@ IntervalTimerImpl::setup(const IntervalTimer::Callback& cbfunc,
// At this point the timer is not running yet and will not expire.
// After calling IOService::run(), the timer will expire.
update();
- return;
}
void
IntervalTimerImpl::update() {
- if (interval_ == 0) {
- // timer has been canceled. Do nothing.
- return;
- }
try {
// Update expire time to (current time + interval_).
timer_.expires_from_now(boost::posix_time::millisec(interval_));
+ // Reset timer.
+ // Pass a function bound with a shared_ptr to this.
+ timer_.async_wait(boost::bind(&IntervalTimerImpl::callback,
+ shared_from_this(),
+ asio::placeholders::error));
} catch (const asio::system_error& e) {
- isc_throw(isc::Unexpected, "Failed to update timer");
+ isc_throw(isc::Unexpected, "Failed to update timer: " << e.what());
+ } catch (const boost::bad_weak_ptr&) {
+ // Can't happen. It means a severe internal bug.
+ assert(0);
}
- // Reset timer.
- timer_.async_wait(boost::bind(&IntervalTimerImpl::callback, this, _1));
}
void
-IntervalTimerImpl::callback(const asio::error_code& cancelled) {
- // Do not call cbfunc_ in case the timer was cancelled.
- // The timer will be canelled in the destructor of asio::deadline_timer.
- if (!cancelled) {
- cbfunc_();
+IntervalTimerImpl::callback(const asio::error_code& ec) {
+ assert(interval_ != INVALIDATED_INTERVAL);
+ if (interval_ == 0 || ec) {
+ // timer has been canceled. Do nothing.
+ } else {
// Set next expire time.
update();
+ // Invoke the call back function.
+ cbfunc_();
}
}
-IntervalTimer::IntervalTimer(IOService& io_service) {
- impl_ = new IntervalTimerImpl(io_service);
-}
+IntervalTimer::IntervalTimer(IOService& io_service) :
+ impl_(new IntervalTimerImpl(io_service))
+{}
IntervalTimer::~IntervalTimer() {
- delete impl_;
+ // Cancel the timer to make sure cbfunc_() will not be called any more.
+ cancel();
}
void
diff --git a/src/lib/asiolink/interval_timer.h b/src/lib/asiolink/interval_timer.h
index 8de16cb..57ec1c3 100644
--- a/src/lib/asiolink/interval_timer.h
+++ b/src/lib/asiolink/interval_timer.h
@@ -16,6 +16,7 @@
#define __ASIOLINK_INTERVAL_TIMER_H 1
#include <boost/function.hpp>
+#include <boost/shared_ptr.hpp>
#include <asiolink/io_service.h>
@@ -42,9 +43,6 @@ class IntervalTimerImpl;
/// The call back function will not be called if the instance of this class is
/// destroyed before the timer is expired.
///
-/// Note: Destruction of an instance of this class while call back is pending
-/// causes throwing an exception from \c IOService.
-///
/// Sample code:
/// \code
/// void function_to_call_back() {
@@ -100,12 +98,12 @@ public:
/// \param interval Interval in milliseconds (greater than 0)
///
/// Note: IntervalTimer will not pass \c asio::error_code to
- /// call back function. In case the timer is cancelled, the function
+ /// call back function. In case the timer is canceled, the function
/// will not be called.
///
/// \throw isc::InvalidParameter cbfunc is empty
/// \throw isc::BadValue interval is less than or equal to 0
- /// \throw isc::Unexpected ASIO library error
+ /// \throw isc::Unexpected internal runtime error
void setup(const Callback& cbfunc, const long interval);
/// Cancel the timer.
@@ -127,7 +125,7 @@ public:
long getInterval() const;
private:
- IntervalTimerImpl* impl_;
+ boost::shared_ptr<IntervalTimerImpl> impl_;
};
} // namespace asiolink
More information about the bind10-changes
mailing list