Skip to content
This repository was archived by the owner on Dec 18, 2018. It is now read-only.

[Needs Tests] Add timeouts #485

Closed
wants to merge 1 commit into from
Closed

Conversation

benaadams
Copy link
Contributor

For #464, #483, #484

Still needs

  • KeepAliveTimeout
  • HeadersCompleteTimeout
  • ExecutionTimeout
  • Read from config
  • Handle bad config
  • Switching off on Upgrades (e.g. WebSockets)
  • Cancelled/Aborted Exception (Easier to distinguish connection close events over more troubling errors)
  • Tests

}
protected int TransitionToState(int state)
{
#pragma warning disable CS0420 // A reference to a volatile field will not be treated as volatile
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't disabling this potentially dangerous?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is a spurious compile warning though perhaps I can just go
int prevState = _frameState;
rather than
int prevState = Volatile.Read(ref _frameState);
and not get the error

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, my worry is that passing volatile fields as ref (or out) may have different behavior on different CPU architectures.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now you raise is... changed to normal int and changed all reads to Volatile.Read as while volatile gives compiler guarantees which is enough on Intel; it doesn't give CPU guarantees which may nor be enough on arm. (Don't know how the traditional C# memory memory model works on other chipssets). Also I'm using the value with Interlocked which wants ref

Also I've rolled two flags into one state and added some extras; so safety first.

@benaadams benaadams force-pushed the timeouts branch 2 times, most recently from 07c3768 to 13dc4ef Compare December 15, 2015 03:08
@benaadams
Copy link
Contributor Author

Added keep-alive as: server.keepAliveTimeout also server.executionTimeout
However as kestrel.headersCompleteTimeout
That work?

{
SocketInput?.AbortAwaiting();
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: add newline

@benaadams benaadams force-pushed the timeouts branch 2 times, most recently from 6dfcabc to c8566a2 Compare January 12, 2016 03:18
@benaadams
Copy link
Contributor Author

Just need to add tests (I think)

@cesarblum
Copy link
Contributor

Yes, please 😄

@benaadams
Copy link
Contributor Author

Check pointing. Still needs more work in light of #566 (comment)

@benaadams
Copy link
Contributor Author

Should have it finished tomorrow.

@@ -388,6 +387,22 @@ void ISocketOutput.Write(ArraySegment<byte> buffer, bool immediate, bool chunk)

Task ISocketOutput.WriteAsync(ArraySegment<byte> buffer, bool immediate, bool chunk, CancellationToken cancellationToken)
{
if (cancellationToken.IsCancellationRequested)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We want to register with the cancellation token for writes that actually result in an incomplete task being returned.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done; not sure perf effects; but on the plus side I've removed some boxing and unboxing 😜

@benaadams
Copy link
Contributor Author

Checkpoint

@@ -238,6 +239,14 @@ public void GetResult()
var error = _awaitableError;
if (error != null)
{
if (error is OperationCanceledException)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wrong error handling

@benaadams
Copy link
Contributor Author

Question on how to handle error in ProducingStart

@benaadams
Copy link
Contributor Author

build stalls when merged with the dotnet update - investigating

@cesarblum
Copy link
Contributor

😞 Try setting NO_PARALLEL_TEST_PROJECTS=Microsoft.AspNetCore.Server.Kestrel.FunctionalTests (env. variable).

@benaadams
Copy link
Contributor Author

Having a little look as it works without the merge; trying just upping threads e.g.
set ComPlus_ThreadPool_ForceMinWorkerThreads=2000


private static TimeSpan GetTimeout(IConfiguration configuration, string configurationKey, int defaultSeconds)
{
var timeoutString = configuration[configurationKey];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not pass timeoutString directly to this method?

@benaadams
Copy link
Contributor Author

Thread count didn't help; got a failed restore second time; third time (without MinWorkerThreads or NO_PARALLEL_TEST_PROJECTS) it was happy...

Might be a dotnet cli issue instead

@cesarblum
Copy link
Contributor

@benaadams Yeah, we think it might be dotnet, or the xunit console runner is doing something funny.

@cesarblum
Copy link
Contributor

@benaadams Did you see it hang consistently? I've only seen it hang on AppVeyor, can't repro on my box.

@benaadams
Copy link
Contributor Author

No; but also get on/off restore issues with Build when starting with a fresh repo; it seems a little shaky atm compared to the dnu version

(e.g. delete directory; then do fresh get from github)

@halter73
Copy link
Member

We should be able to add this for rc2. Do you still think you can write some test cases for this? Thanks!

@benaadams
Copy link
Contributor Author

I'd like advice on test cases; waiting for timeouts and CI never seem to mix well...

@benaadams
Copy link
Contributor Author

To clarify further; the timeouts are in seconds so can't go finer than that; and CI is flakey with timeout numbers ;-/

Write write some see how it goes

@halter73
Copy link
Member

I would make timeouts very short (maybe a tenth of a second) and verify that you get 500 responses (header timeout) or the that connection is gracefully (keepalive timeout)/ungracefully(execution timeout). Also verify that ongoing reads get aborted in the event you are in the executing phase.

You can be very generous with the amount of time you wait for the timeouts to trigger. I wouldn't mind if we waited 10 seconds (100 times what they are set to) for the timeouts to trigger. Hopefully that will be long enough for travis/appveyor. If not, we can adjust.

@halter73
Copy link
Member

Oh. And this isn't urgent. Feel free to wait until we get AppVeyor and Travis passing again (maybe someday 😞) so you can verify the timeouts work.

@benaadams
Copy link
Contributor Author

Obviously I need to get it in before #623 - think of the merge! ;-)

@benaadams benaadams changed the title [Wip] Add timeouts [Needs Tests] Add timeouts Feb 12, 2016
@benaadams
Copy link
Contributor Author

/cc @halter73 away for a week; so won't be able to rebase or make changes during that time.

using Microsoft.AspNetCore.Server.Kestrel.Filter;

namespace Microsoft.AspNetCore.Server.Kestrel
{
public interface IKestrelServerInformation
{
TimeSpan ExecutionTimeout { get; set; }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

KeepAlive and HeadersComplete are reasonable, but I don't think we need or want ExecutionTimeout at the server level.
A) The same functionality can be provided in app/middleware code.
B) The timeout is un-enforceable. You can't force an app to abandon a request, you can only close the socket and trip the token. The RequestAborted CancellationToken is at best a hint. There are no thread aborts like v4.
C) There are known scenarios this breaks with long running requests. It's one more setting on the server to hunt down and fiddle with when that happens.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🆗

@muratg muratg modified the milestones: 1.0.0, 1.0.0-rc2 Apr 8, 2016
@benaadams
Copy link
Contributor Author

benaadams commented May 24, 2016

@muratg @halter73 @CesarBS going to close this as realistically I won't have enough time to devote to it; the underlying code has changed a lot and there are multiple potential race conditions which have to be guarded against - so will need a lot of testing

@MelbourneDeveloper
Copy link

I'm pretty confused. Is there currently an ExecutionTimeout in Kestrel? If so, how to we stop it, or change it?

I'm getting a WCF timeout that I can't explain unless it's something going on with a Kestrel request timeout.

@davidfowl
Copy link
Member

There's no execution timeout in kestrel (which isn't possible to do with async requests because if there's no thread running then there's nothing to time out). How would kestrel affect your WCF service? The ASP.NET core module has a 2 minute timeout for requests, maybe you're running into that?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants