Skip to content

Commit 95e6776

Browse files
author
Connor McMahon
authored
Fix bug in new Webhook URL fetch logic (#1740)
The context.GetWebhookUrl() method only works in the context of the Initialize() method. In order to properly handle this case, we must use the direct IWebhookProvider made available in FunctionsV2+, and in FunctionsV1 we have to live with the fact that we can't dynamically determine the current webhook URI.
1 parent 9d404c6 commit 95e6776

File tree

4 files changed

+25
-7
lines changed

4 files changed

+25
-7
lines changed

release_notes.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
- Improved concurrency defaults for the App Service Consumption plan (https://github.com/Azure/azure-functions-durable-extension/pull/1706)
44

55
## Bug Fixes:
6-
- Properly used update management API URLs after a successful slot swap (#1716)
6+
- Properly used update management API URLs after a successful slot swap on Functions V3 (#1716)
77
- Fix race condition when multiple apps start with local RPC endpoints on the same VM in parallel. (#1719)
88
- Fix CallHttpAsync() to throw an HttpRequestException instead of a serialization exception if the target endpoint doesn't exist (#1718)
99

src/WebJobs.Extensions.DurableTask/DurableTaskExtension.cs

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ public DurableTaskExtension()
111111
/// <param name="lifeCycleNotificationHelper">The lifecycle notification helper used for custom orchestration tracking.</param>
112112
/// <param name="messageSerializerSettingsFactory">The factory used to create <see cref="JsonSerializerSettings"/> for message settings.</param>
113113
/// <param name="errorSerializerSettingsFactory">The factory used to create <see cref="JsonSerializerSettings"/> for error settings.</param>
114+
/// <param name="webhookProvider">Provides webhook urls for HTTP management APIs.</param>
114115
/// <param name="telemetryActivator">The activator of DistributedTracing. .netstandard2.0 only.</param>
115116
/// <param name="platformInformationService">The platform information provider to inspect the OS, app service plan, and other enviroment information.</param>
116117
#pragma warning restore CS1572
@@ -128,10 +129,12 @@ public DurableTaskExtension(
128129
#pragma warning restore CS0612 // Type or member is obsolete
129130
#if !FUNCTIONS_V1
130131
IErrorSerializerSettingsFactory errorSerializerSettingsFactory = null,
132+
#pragma warning disable CS0618 // Type or member is obsolete
133+
IWebHookProvider webhookProvider = null,
134+
#pragma warning restore CS0618 // Type or member is obsolete
131135
#pragma warning disable SA1113, SA1001, SA1115
132136
ITelemetryActivator telemetryActivator = null)
133137
#pragma warning restore SA1113, SA1001, SA1115
134-
135138
#else
136139
IErrorSerializerSettingsFactory errorSerializerSettingsFactory = null)
137140
#endif
@@ -163,6 +166,14 @@ public DurableTaskExtension(
163166
this.ErrorDataConverter = this.CreateErrorDataConverter(errorSerializerSettingsFactory);
164167

165168
this.HttpApiHandler = new HttpApiHandler(this, logger);
169+
#if !FUNCTIONS_V1
170+
// This line ensure every time we need the webhook URI, we get it directly from the
171+
// function runtime, which has the most up-to-date knowledge about the site hostname.
172+
Func<Uri> webhookDelegate = () => webhookProvider.GetUrl(this);
173+
this.HttpApiHandler.RegisterWebhookProvider(
174+
this.Options.WebhookUriProviderOverride ??
175+
webhookDelegate);
176+
#endif
166177

167178
this.hostLifetimeService = hostLifetimeService;
168179

@@ -314,13 +325,18 @@ void IExtensionConfigProvider.Initialize(ExtensionConfigContext context)
314325
#pragma warning disable CS0618 // Type or member is obsolete
315326

316327
// Invoke webhook handler to make functions runtime register extension endpoints.
317-
context.GetWebhookHandler();
328+
var initialWebhookUri = context.GetWebhookHandler();
318329

319-
// This line ensure every time we need the webhook URI, we get it directly from the
320-
// function runtime, which has the most up-to-date knowledge about the site hostname.
330+
#if FUNCTIONS_V1
331+
// In Functions V1, there is no notion of an IWebhookProvider that
332+
// we can dynamically call to fetch the webhook URI, and since context.GetWebhookHandler()
333+
// only works in the scope of the Initialize() function, we just have to live with the static URI
334+
// we grab now.
335+
Func<Uri> staticWebhookHandler = () => initialWebhookUri;
321336
this.HttpApiHandler.RegisterWebhookProvider(
322337
this.Options.WebhookUriProviderOverride ??
323-
context.GetWebhookHandler);
338+
staticWebhookHandler);
339+
#endif
324340
#pragma warning restore CS0618 // Type or member is obsolete
325341

326342
this.TraceConfigurationSettings();

src/WebJobs.Extensions.DurableTask/Microsoft.Azure.WebJobs.Extensions.DurableTask-net461.xml

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/WebJobs.Extensions.DurableTask/Microsoft.Azure.WebJobs.Extensions.DurableTask.xml

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)