-
Notifications
You must be signed in to change notification settings - Fork 466
[WIP] Flow cancellation token to PendingItem #11196
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
Draft
liliankasem
wants to merge
1
commit into
dev
Choose a base branch
from
liliankasem/bug/pendingitem-cancellation
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ | |
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Reactive.Linq; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using Microsoft.Azure.AppService.Proxy.Common.Infra; | ||
using Microsoft.Azure.WebJobs.Script.Config; | ||
|
@@ -72,22 +73,24 @@ public WebHostRpcWorkerChannelManager(IScriptEventManager eventManager, | |
_shutdownStandbyWorkerChannels = _shutdownStandbyWorkerChannels.Debounce(milliseconds: 5000); | ||
} | ||
|
||
public Task<IRpcWorkerChannel> InitializeChannelAsync(IEnumerable<RpcWorkerConfig> workerConfigs, string runtime) | ||
public Task<IRpcWorkerChannel> InitializeChannelAsync(IEnumerable<RpcWorkerConfig> workerConfigs, string runtime, CancellationToken cancellationToken = default) | ||
{ | ||
_logger?.LogDebug("Initializing language worker channel for runtime:{runtime}", runtime); | ||
return InitializeLanguageWorkerChannel(workerConfigs, runtime, _applicationHostOptions.CurrentValue.ScriptPath); | ||
return InitializeLanguageWorkerChannel(workerConfigs, runtime, _applicationHostOptions.CurrentValue.ScriptPath, cancellationToken); | ||
} | ||
|
||
internal async Task<IRpcWorkerChannel> InitializeLanguageWorkerChannel(IEnumerable<RpcWorkerConfig> workerConfigs, string runtime, string scriptRootPath) | ||
internal async Task<IRpcWorkerChannel> InitializeLanguageWorkerChannel(IEnumerable<RpcWorkerConfig> workerConfigs, string runtime, string scriptRootPath, CancellationToken cancellationToken = default) | ||
{ | ||
cancellationToken.ThrowIfCancellationRequested(); | ||
|
||
IRpcWorkerChannel rpcWorkerChannel = null; | ||
string workerId = Guid.NewGuid().ToString(); | ||
_logger.LogDebug("Creating language worker channel for runtime:{runtime}", runtime); | ||
_logger.LogWarning("Creating language worker channel for runtime:{runtime}", runtime); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. revert |
||
try | ||
{ | ||
rpcWorkerChannel = _rpcWorkerChannelFactory.Create(scriptRootPath, runtime, _metricsLogger, 0, workerConfigs); | ||
AddOrUpdateWorkerChannels(runtime, rpcWorkerChannel); | ||
await rpcWorkerChannel.StartWorkerProcessAsync().ContinueWith(processStartTask => | ||
await rpcWorkerChannel.StartWorkerProcessAsync(cancellationToken).ContinueWith(processStartTask => | ||
{ | ||
if (processStartTask.Status == TaskStatus.RanToCompletion) | ||
{ | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So my idea was to pass the
_applicationLifetime.ApplicationStopping
CT toStartWorkerProcessAsync
-> PendingItem. (it doesn't have to come throughWorkerFunctionMetadataProvider
so let me know if you have better ideas)The problem I am seeing with this is that when I cancel (exit the host) we don't see CT triggered until after the timeout period of
PendingItem
has run its course. We are blocking in a weird way and we need to get around that block for the CT to flow properly.cc: @jviau @fabiocav