Skip to content

Commit

Permalink
BUG 34413423 - [33982984->14.1.1.0.10] Service.OnExit() may throw NPE…
Browse files Browse the repository at this point in the history
… intermittently (main.net cl 91143 --> 14.1.1.0)

[git-p4: depot-paths = "//dev/release.net/coherence-net-v14.1.1.0/": change = 94496]
  • Loading branch information
fryp committed Jul 22, 2022
1 parent 2e52404 commit e1a377a
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 3 deletions.
43 changes: 41 additions & 2 deletions src/Coherence/Util/Daemon/Daemon.cs
Original file line number Diff line number Diff line change
Expand Up @@ -590,7 +590,7 @@ public virtual void Stop()
// Once IsExiting is set the daemon's thread will attempt to clear any interrupts and then proceed to OnExit.
// In order to ensure that this doesn't occur before we actually get to interrupt the thread we synchronize this method
// as well as Run's call to clear the interrupt.
lock (ExitMonitor)
using (BlockingLock l = BlockingLock.Lock(ExitMonitor))
{
// only go through Stop() once to prevent spurious interrupts during OnExit()
if (!IsExiting)
Expand All @@ -611,6 +611,45 @@ public virtual void Stop()
}
}

/// <summary>
/// Wait for the Daemon thread to stop.
/// </summary>
///
/// <param name="millis">
/// The number of milliseconds to wait for, or zero for infinite.
/// </param>
///
/// <returns>
/// <b>true</b> if the thread is no longer running.
/// </returns>
///
/// <since>Coherence 14.1.2.0</since>
public virtual bool Join(int millis)
{
try
{
Thread thread = this.Thread;
if (thread != null)
{
if (millis > 0)
{
thread.Join(millis);
}
else
{
thread.Join();
}
return !thread.IsAlive;
}
return true;
}
catch (ThreadInterruptedException)
{
Thread.CurrentThread.Interrupt();
return false;
}
}

/// <summary>
/// This method is called right after this daemon's thread starts.
/// </summary>
Expand Down Expand Up @@ -669,7 +708,7 @@ public virtual void Run()
try
{
// see comment in Stop()
lock (ExitMonitor)
using (BlockingLock l = BlockingLock.Lock(ExitMonitor))
{
try
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -647,7 +647,7 @@ protected override void OnExit()
// give the chance for the daemon to drain it's queue
try
{
daemon.Thread.Join(1000);
daemon.Join(1000);
}
catch (ThreadInterruptedException)
{
Expand Down

0 comments on commit e1a377a

Please sign in to comment.