Skip to content

Commit 1cfab67

Browse files
committed
Fixed AutoScale timer not stopping Redth#36
The PushServiceBase uses a timer to check the scale (if autoscaling is enabled). This timer was not being stopped once the service itself was stopped and could cause exceptions to be thrown if the timer fired after a service was stopped.
1 parent d157871 commit 1cfab67

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

Diff for: PushSharp.Common/PushServiceBase.cs

+7-3
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,10 @@ public void Stop(bool waitForQueueToFinish)
6262
{
6363
stopping = true;
6464

65+
//Stop the timer for checking scale
66+
if (this.timerCheckScale != null)
67+
this.timerCheckScale.Change(Timeout.Infinite, Timeout.Infinite);
68+
6569
//Stop all channels
6670
Parallel.ForEach<PushChannelBase>(channels,
6771
(channel) =>
@@ -125,7 +129,7 @@ orderby c.QueuedNotificationCount
125129

126130
void CheckScale()
127131
{
128-
if (ServiceSettings.AutoScaleChannels)
132+
if (ServiceSettings.AutoScaleChannels && !this.cancelTokenSource.IsCancellationRequested && !stopping)
129133
{
130134
if (channels.Count <= 0)
131135
{
@@ -158,10 +162,10 @@ void CheckScale()
158162
}
159163
else
160164
{
161-
while (channels.Count > ServiceSettings.Channels)
165+
while (channels.Count > ServiceSettings.Channels && !this.cancelTokenSource.IsCancellationRequested && !stopping)
162166
TeardownChannel();
163167

164-
while (channels.Count < ServiceSettings.Channels)
168+
while (channels.Count < ServiceSettings.Channels && !this.cancelTokenSource.IsCancellationRequested && !stopping)
165169
SpinupChannel();
166170
}
167171
}

0 commit comments

Comments
 (0)