Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Streamed Timeout TimeSpan.MaxValue Exception #5618

Merged
merged 2 commits into from
Aug 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -118,4 +118,42 @@ public static void ReceiveTimeout_Applied()
ScenarioTestHelpers.CloseCommunicationObjects((ICommunicationObject)serviceProxy, factory);
}
}

// Test for https://github.com/CoreWCF/CoreWCF/issues/1391
[WcfFact]
[OuterLoop]
public static void SecurityModeNone_Echo_RoundTrips_String_Stream_TimeoutMaxValue()
{
string testString = "Hello";
ChannelFactory<IWcfServiceGenerated> factory = null;
IWcfServiceGenerated serviceProxy = null;

try
{
// *** SETUP *** \\
var binding = new NetTcpBinding(SecurityMode.None)
{
SendTimeout = TimeSpan.MaxValue,
ReceiveTimeout = TimeSpan.MaxValue
};
binding.Security.Transport.ClientCredentialType = TcpClientCredentialType.None;
binding.TransferMode = TransferMode.Streamed;

factory = new ChannelFactory<IWcfServiceGenerated>(binding, new EndpointAddress(Endpoints.Tcp_Streamed_NoSecurity_Address));
serviceProxy = factory.CreateChannel();

// *** EXECUTE *** \\
string result = serviceProxy.Echo(testString);
Assert.Equal(testString, result);

// *** CLEANUP *** \\
((ICommunicationObject)serviceProxy).Close();
factory.Close();
}
finally
{
// *** ENSURE CLEANUP *** \\
ScenarioTestHelpers.CloseCommunicationObjects((ICommunicationObject)serviceProxy, factory);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ private void CancelTimer()
{
if (_idleTimer != null)
{
_idleTimer.Change(TimeSpan.FromMilliseconds(-1), TimeSpan.FromMilliseconds(-1));
_idleTimer.Change(Timeout.InfiniteTimeSpan, Timeout.InfiniteTimeSpan);
}
}

Expand All @@ -180,11 +180,11 @@ private void StartTimerIfNecessary()
s_onIdle = new Action<object>(OnIdle);
}

_idleTimer = new Timer(new TimerCallback(new Action<object>(s_onIdle)), this, _idleTimeout, TimeSpan.FromMilliseconds(-1));
_idleTimer = new Timer(new TimerCallback(new Action<object>(s_onIdle)), this, _idleTimeout, Timeout.InfiniteTimeSpan);
}
else
{
_idleTimer.Change(_idleTimeout, TimeSpan.FromMilliseconds(-1));
_idleTimer.Change(_idleTimeout, Timeout.InfiniteTimeSpan);
}
}
}
Expand Down Expand Up @@ -267,7 +267,7 @@ public void Prune(List<TItem> itemsToClose, bool calledFromTimer)

if (calledFromTimer && setTimer)
{
_idleTimer.Change(_idleTimeout, TimeSpan.FromMilliseconds(-1));
_idleTimer.Change(_idleTimeout, Timeout.InfiniteTimeSpan);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -623,7 +623,7 @@ private ValueTask WriteChunkSizeAsync(int size)
if (size > 0)
{
int bytesEncoded = IntEncoder.Encode(size, _encodedSize);
return Connection.WriteAsync(_encodedSize.Slice(0, bytesEncoded), false, TimeSpan.FromMilliseconds(WriteTimeout));
return Connection.WriteAsync(_encodedSize.Slice(0, bytesEncoded), false, TimeoutHelper.FromMilliseconds(WriteTimeout));
}
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -907,7 +907,7 @@ public AsyncQueueReader(InputQueue<T> inputQueue, TimeSpan timeout, AsyncCallbac
_inputQueue = inputQueue;
if (timeout != TimeSpan.MaxValue)
{
_timer = new Timer(new TimerCallback(s_timerCallback), this, timeout, TimeSpan.FromMilliseconds(-1));
_timer = new Timer(new TimerCallback(s_timerCallback), this, timeout, Timeout.InfiniteTimeSpan);
}
}

Expand All @@ -932,7 +932,7 @@ public void Set(Item item)
_item = item.Value;
if (_timer != null)
{
_timer.Change(TimeSpan.FromMilliseconds(-1), TimeSpan.FromMilliseconds(-1));
_timer.Change(Timeout.InfiniteTimeSpan, Timeout.InfiniteTimeSpan);
}
Complete(false, item.Exception);
}
Expand All @@ -958,7 +958,7 @@ public AsyncQueueWaiter(TimeSpan timeout, AsyncCallback callback, object state)
{
if (timeout != TimeSpan.MaxValue)
{
_timer = new Timer(new TimerCallback(s_timerCallback), this, timeout, TimeSpan.FromMilliseconds(-1));
_timer = new Timer(new TimerCallback(s_timerCallback), this, timeout, Timeout.InfiniteTimeSpan);
}
}

Expand All @@ -976,7 +976,7 @@ public void Set(bool itemAvailable)

lock (ThisLock)
{
timely = (_timer == null) || _timer.Change(TimeSpan.FromMilliseconds(-1), TimeSpan.FromMilliseconds(-1));
timely = (_timer == null) || _timer.Change(Timeout.InfiniteTimeSpan, Timeout.InfiniteTimeSpan);
_itemAvailable = itemAvailable;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2339,7 +2339,7 @@ internal AsyncWaiter(CallOnceManager manager, TimeSpan timeout,

if (timeout != TimeSpan.MaxValue)
{
_timer = new Timer(s_timeoutCallback, this, timeout, TimeSpan.FromMilliseconds(-1));
_timer = new Timer(s_timeoutCallback, this, timeout, Timeout.InfiniteTimeSpan);
}
}

Expand All @@ -2350,7 +2350,7 @@ internal static void End(IAsyncResult result)

void IWaiter.Signal()
{
if ((_timer == null) || _timer.Change(TimeSpan.FromMilliseconds(-1), TimeSpan.FromMilliseconds(-1)))
if ((_timer == null) || _timer.Change(Timeout.InfiniteTimeSpan, Timeout.InfiniteTimeSpan))
{
Complete(false);
_manager._channel.Closed -= OnClosed;
Expand All @@ -2363,7 +2363,7 @@ void IWaiter.Signal()

private void OnClosed(object sender, EventArgs e)
{
if ((_timer == null) || _timer.Change(TimeSpan.FromMilliseconds(-1), TimeSpan.FromMilliseconds(-1)))
if ((_timer == null) || _timer.Change(Timeout.InfiniteTimeSpan, Timeout.InfiniteTimeSpan))
{
Complete(false, _manager._channel.CreateClosedException());
}
Expand Down Expand Up @@ -2406,7 +2406,7 @@ internal class SessionIdleManager
private SessionIdleManager(IChannelBinder binder, TimeSpan idle)
{
_binder = binder;
_timer = new Timer(new TimerCallback(GetTimerCallback()), this, idle, TimeSpan.FromMilliseconds(-1));
_timer = new Timer(new TimerCallback(GetTimerCallback()), this, idle, Timeout.InfiniteTimeSpan);
_idleTicks = Ticks.FromTimeSpan(idle);
_thisLock = new Object();
}
Expand Down Expand Up @@ -2439,7 +2439,7 @@ internal void CancelTimer()
lock (_thisLock)
{
_isTimerCancelled = true;
_timer.Change(TimeSpan.FromMilliseconds(-1), TimeSpan.FromMilliseconds(-1));
_timer.Change(Timeout.InfiniteTimeSpan, Timeout.InfiniteTimeSpan);
}
}

Expand Down Expand Up @@ -2508,7 +2508,7 @@ private void TimerCallback()
{
if (!_isTimerCancelled && _binder.Channel.State != CommunicationState.Faulted && _binder.Channel.State != CommunicationState.Closed)
{
_timer.Change(Ticks.ToTimeSpan(abortTime - ticksNow), TimeSpan.FromMilliseconds(-1));
_timer.Change(Ticks.ToTimeSpan(abortTime - ticksNow), Timeout.InfiniteTimeSpan);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -822,7 +822,7 @@ internal AsyncDuplexRequest(Message message, DuplexChannelBinder parent, TimeSpa

if (timeout != TimeSpan.MaxValue)
{
_timer = new Timer(new TimerCallback(AsyncDuplexRequest.s_timerCallback), this, timeout, TimeSpan.FromMilliseconds(-1));
_timer = new Timer(new TimerCallback(AsyncDuplexRequest.s_timerCallback), this, timeout, Timeout.InfiniteTimeSpan);
}
if (DiagnosticUtility.ShouldUseActivity)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ internal void AfterReply(ref MessageRpc rpc)
{
if (rpc.Operation.IsTerminating && rpc.Channel.HasSession)
{
var timer = new Timer(s_abortChannelTimerCallback, rpc.Channel.Binder.Channel, rpc.Channel.CloseTimeout, TimeSpan.FromMilliseconds(-1));
var timer = new Timer(s_abortChannelTimerCallback, rpc.Channel.Binder.Channel, rpc.Channel.CloseTimeout, Timeout.InfiniteTimeSpan);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ private void CancelTimerIfNeeded()
{
if (Count == 0 && _purgingTimer != null)
{
_purgingTimer.Change(TimeSpan.FromMilliseconds(-1), TimeSpan.FromMilliseconds(-1));
_purgingTimer.Change(Timeout.InfiniteTimeSpan, Timeout.InfiniteTimeSpan);
_purgingTimer.Dispose();
_purgingTimer = null;
}
Expand All @@ -90,7 +90,7 @@ private void StartTimerIfNeeded()
}
if (_purgingTimer == null)
{
_purgingTimer = new Timer(new TimerCallback(PurgeCallback), this, _purgeInterval, TimeSpan.FromMilliseconds(-1));
_purgingTimer = new Timer(new TimerCallback(PurgeCallback), this, _purgeInterval, Timeout.InfiniteTimeSpan);
}
}

Expand Down Expand Up @@ -420,7 +420,7 @@ private static void PurgeCallbackStatic(object state)
self.PurgeStaleItems();
if (self.Count > 0 && self._purgingTimer != null)
{
self._purgingTimer.Change(self._purgeInterval, TimeSpan.FromMilliseconds(-1));
self._purgingTimer.Change(self._purgeInterval, Timeout.InfiniteTimeSpan);
}
}
finally
Expand Down