Work at SourceForge, help us to make it a better place! We have an immediate need for a Support Technician in our San Francisco or Denver office.

Close

#274 Dispose for FireFoxClientPort can take forever

Version_2.next
open
5
2012-09-15
2011-10-08
Anonymous
No

In some cases WatiN can freze forever on line 537 of FireFoxClientPort.cs.
I think it's because ReadTimeout property is not set for NetworkStream.
Teoretically this situation has to be resolved by using TryFuncUntilTimeOut, but i don't think it works correct. I used simple test for verification:

[Test]
public void ShouldThrowExceptionIfTimeout() {
var to = new TryFuncUntilTimeOut(TimeSpan.FromSeconds(1.0));
var res = to.Try(() => {
Thread.Sleep(TimeSpan.FromSeconds(5.0));
return true;
});
Assert.IsTrue(res);
Assert.IsTrue(to.DidTimeOut);
}

I would recommend you use event based model insted. It can affect performance, but it works.

public static TRes ExecuteWithTimeout<TRes>(this Func<TRes> f, int timeout = 5) where TRes : class {
Exception lastError = null;
TRes result = null;
var evnt = new ManualResetEvent(false);
var t = new Thread(() => {
try {
result = f();
}
catch (Exception ex) {
lastError = ex;
}
evnt.Set();
});
t.Start();
bool r = evnt.WaitOne(TimeSpan.FromSeconds(timeout));
if (null != lastError) throw lastError;
if (!r) {
t.Abort();
throw new TimeoutException("Timeout occur");
}
return result;
}

Discussion