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

Tweak libuv shutdown sequence #1735

Merged
merged 2 commits into from
Apr 21, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -5,7 +5,6 @@
using System.Collections.Generic;
using System.Diagnostics;
using System.Runtime.ExceptionServices;
using System.Runtime.InteropServices;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Hosting;
Expand Down Expand Up @@ -103,15 +102,15 @@ public async Task StopAsync(TimeSpan timeout)
{
var stepTimeout = TimeSpan.FromTicks(timeout.Ticks / 3);

Post(t => t.AllowStop());
await PostAsync(t => t.AllowStop(), this).ConfigureAwait(false);
Copy link
Member

Choose a reason for hiding this comment

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

Won't this prevent StopAsync from completing if the event loop is deadlocked?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, it will. I'll add a check in AllowStop itself. It's safer.

Copy link
Member

Choose a reason for hiding this comment

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

What's the benefit of PostAsync here if we are waiting for _threadTcs.Task to complete anyway?

if (!await WaitAsync(_threadTcs.Task, stepTimeout).ConfigureAwait(false))
{
try
{
Post(t => t.OnStopRude());
await PostAsync(t => t.OnStopRude(), this).ConfigureAwait(false);
if (!await WaitAsync(_threadTcs.Task, stepTimeout).ConfigureAwait(false))
{
Post(t => t.OnStopImmediate());
await PostAsync(t => t.OnStopImmediate(), this).ConfigureAwait(false);
if (!await WaitAsync(_threadTcs.Task, stepTimeout).ConfigureAwait(false))
{
_log.LogCritical($"{nameof(LibuvThread)}.{nameof(StopAsync)} failed to terminate libuv thread.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public async Task StopAsync()
{
try
{
await Task.WhenAll(Threads.Select(thread => thread.StopAsync(TimeSpan.FromSeconds(2.5))).ToArray())
await Task.WhenAll(Threads.Select(thread => thread.StopAsync(TimeSpan.FromSeconds(5))).ToArray())
.ConfigureAwait(false);
}
catch (AggregateException aggEx)
Expand Down Expand Up @@ -123,7 +123,7 @@ public async Task UnbindAsync()
{
var disposeTasks = _listeners.Select(listener => listener.DisposeAsync()).ToArray();

if (!await WaitAsync(Task.WhenAll(disposeTasks), TimeSpan.FromSeconds(2.5)).ConfigureAwait(false))
if (!await WaitAsync(Task.WhenAll(disposeTasks), TimeSpan.FromSeconds(5)).ConfigureAwait(false))
Copy link
Member

Choose a reason for hiding this comment

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

Did you see this being timed out?

Copy link
Member Author

Choose a reason for hiding this comment

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

{
Log.LogError(0, null, "Disposing listeners failed");
}
Expand Down