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

Fixes ByteBuffer+Stream integration, TLS neg, STEE Shutdown #91

Merged
merged 1 commit into from
Apr 27, 2016

Conversation

nayato
Copy link
Member

@nayato nayato commented Apr 27, 2016

Motivation:
Fix up top priority issues to ensure proper working state with recent changes.

Modifications:

Result:
Setting up DotNetty does not require workarounds for shutdown and hacks to enable negotiation of higher versions of TLS. Tests are passing even with new SslStream behavior.

@nayato nayato force-pushed the shutdown branch 3 times, most recently from 1c3e871 to a8f5e7c Compare April 27, 2016 10:14
@@ -120,6 +119,14 @@ public override void Execute(IRunnable task)
}
}

protected void WakeUp(bool inEventLoop)
{
if (!inEventLoop || this.executionState == ST_SHUTTING_DOWN)
Copy link
Contributor

Choose a reason for hiding this comment

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

change to if (!inEventLoop || IsShuttingDown)

Copy link
Member Author

@nayato nayato Apr 27, 2016

Choose a reason for hiding this comment

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

there's difference between IsShuttingDown is >= and WakeUp uses ==

Copy link
Contributor

Choose a reason for hiding this comment

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

ah, right. guess there's no point in waking up after we've terminated.

@Aaronontheweb
Copy link
Contributor

Seeing debug assertions get thrown for this spec in ReSharper as a result of this change:

public class SingleThreadEventExecutorSpecs
    {
        public static AtomicCounter ThreadNameCounter { get; } = new AtomicCounter(0);

        [Fact]
        public void STE_should_complete_task_when_operation_is_completed()
        {
            using (
                var executor = new SingleThreadEventExecutor("Foo" + ThreadNameCounter.GetAndIncrement(),
                    TimeSpan.FromMilliseconds(100)))
            {
                Func<bool> myFunc = () => true;
                var task = executor.SubmitAsync(myFunc);
                Assert.True(task.Wait(200), "Should have completed task in under 200 milliseconds");
                Assert.True(task.Result);
                executor.GracefulShutdownAsync();
            }
        }
}

@Aaronontheweb
Copy link
Contributor

InEventLoop == false during PollTask. Don't have more time to investigate now.

@nayato
Copy link
Member Author

nayato commented Apr 27, 2016

That doesn't make sense... PollTask is run only in a context of Loop: directly or through ConfirmShutdown or through CleanupAndTerminate -> ConfirmShutdown

@Aaronontheweb
Copy link
Contributor

I'm in agreement with you - I'll try to replicate this issue with the normal XUnit runner; so far I've only seen it happen in ReSharper.

@Aaronontheweb
Copy link
Contributor

heh, just realized what it might be - think there could be an issue with the Dispose call on the using statement that causes a race condition here?

@Aaronontheweb
Copy link
Contributor

Since I'm not blocking on the GracefulShutdownAsync ?

@nayato
Copy link
Member Author

nayato commented Apr 27, 2016

makes sense

@nayato
Copy link
Member Author

nayato commented Apr 27, 2016

Not sure if it even makes sense to have it implement IDisposable

@Aaronontheweb
Copy link
Contributor

at the very least, have the IDisposable call gracefulshutdown itself and wait on it.

@nayato
Copy link
Member Author

nayato commented Apr 27, 2016

no, that's just misleading..

@nayato
Copy link
Member Author

nayato commented Apr 27, 2016

I think I introduced impl of IDisposable as a port of ExecutorService.shutdown which is really deprecated. I think it is misleading to have Dispose. IAsyncDisposable would have made sense but we're not there yet.

@nayato
Copy link
Member Author

nayato commented Apr 27, 2016

Funny part is, it didn't even implement IDisposable. Just the Dispose method was there.

@nayato
Copy link
Member Author

nayato commented Apr 27, 2016

I'm removing Dispose, will post a new version in a sec.

Motivation:
Fix up top priority issues to ensure proper working state with recent changes.

Modifications:
- TlsHandler negotiates TLS 1.0+ on server side (Azure#89)
- STEE properly supports graceful shutdown (Azure#7)
- UnpooledHeapByteBuffer.GetBytes honors received index and length (Azure#88)
- Echo E2E test uses length-prefix based framing (Azure#90)

Result:
Setting up DotNetty does not require workarounds for shutdown and hacks to enable negotiation of higher versions of TLS. Tests are passing even with new SslStream behavior.
@Aaronontheweb
Copy link
Contributor

no, that's just misleading..

I don't agree with that - I'd expect the result of the call to be that the object is finalized and ready for garbage collection when the method exits.

@Aaronontheweb
Copy link
Contributor

I'm removing Dispose, will post a new version in a sec.

👍

@nayato
Copy link
Member Author

nayato commented Apr 27, 2016

Dispose is meant for lightweight teardown though. Blocking call that might not return in 5 seconds (default shutdown timeout) might result in confusion. Better have a clear non-standard way of doing shutdown for now. Once IAsyncDisposable comes around, we'll support that as it sets right expectations and allows for non-blocking signaling of shutdown completion.

@Aaronontheweb
Copy link
Contributor

Dispose is meant for lightweight teardown though. Blocking call that might not return in 5 seconds (default shutdown timeout) might result in confusion.

Yeah, that's true - if the teardown takes sufficiently long that would be undesirable too. I agree with what you've done here.

@mtuchkov
Copy link
Contributor

LGTM

@nayato nayato merged commit 66caa64 into Azure:dev Apr 27, 2016
@nayato nayato deleted the shutdown branch May 6, 2016 02:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants