Skip to content

Commit e1a377a

Browse files
committed
BUG 34413423 - [33982984->14.1.1.0.10] Service.OnExit() may throw NPE intermittently (main.net cl 91143 --> 14.1.1.0)
[git-p4: depot-paths = "//dev/release.net/coherence-net-v14.1.1.0/": change = 94496]
1 parent 2e52404 commit e1a377a

File tree

2 files changed

+42
-3
lines changed

2 files changed

+42
-3
lines changed

src/Coherence/Util/Daemon/Daemon.cs

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -590,7 +590,7 @@ public virtual void Stop()
590590
// Once IsExiting is set the daemon's thread will attempt to clear any interrupts and then proceed to OnExit.
591591
// In order to ensure that this doesn't occur before we actually get to interrupt the thread we synchronize this method
592592
// as well as Run's call to clear the interrupt.
593-
lock (ExitMonitor)
593+
using (BlockingLock l = BlockingLock.Lock(ExitMonitor))
594594
{
595595
// only go through Stop() once to prevent spurious interrupts during OnExit()
596596
if (!IsExiting)
@@ -611,6 +611,45 @@ public virtual void Stop()
611611
}
612612
}
613613

614+
/// <summary>
615+
/// Wait for the Daemon thread to stop.
616+
/// </summary>
617+
///
618+
/// <param name="millis">
619+
/// The number of milliseconds to wait for, or zero for infinite.
620+
/// </param>
621+
///
622+
/// <returns>
623+
/// <b>true</b> if the thread is no longer running.
624+
/// </returns>
625+
///
626+
/// <since>Coherence 14.1.2.0</since>
627+
public virtual bool Join(int millis)
628+
{
629+
try
630+
{
631+
Thread thread = this.Thread;
632+
if (thread != null)
633+
{
634+
if (millis > 0)
635+
{
636+
thread.Join(millis);
637+
}
638+
else
639+
{
640+
thread.Join();
641+
}
642+
return !thread.IsAlive;
643+
}
644+
return true;
645+
}
646+
catch (ThreadInterruptedException)
647+
{
648+
Thread.CurrentThread.Interrupt();
649+
return false;
650+
}
651+
}
652+
614653
/// <summary>
615654
/// This method is called right after this daemon's thread starts.
616655
/// </summary>
@@ -669,7 +708,7 @@ public virtual void Run()
669708
try
670709
{
671710
// see comment in Stop()
672-
lock (ExitMonitor)
711+
using (BlockingLock l = BlockingLock.Lock(ExitMonitor))
673712
{
674713
try
675714
{

src/Coherence/Util/Daemon/QueueProcessor/Service/Service.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -647,7 +647,7 @@ protected override void OnExit()
647647
// give the chance for the daemon to drain it's queue
648648
try
649649
{
650-
daemon.Thread.Join(1000);
650+
daemon.Join(1000);
651651
}
652652
catch (ThreadInterruptedException)
653653
{

0 commit comments

Comments
 (0)