Azure / Azure/azure-functions-host

Handling the return value from an orchestrator function in Custom Handler without `$return` binding difinition in function.json

Open
#7,684 2 comments 1 reaction 0 assignees View on GitHub
Dominant language
C#
Stars
2k
Forks
482
Avg merge
2d 12h
Merged PRs (30d)
38

Description

#### What problem would the feature you're requesting solve? Please describe.
Now I'm trying to port [Durable Functions for Node.js](https://github.com/Azure/azure-functions-durable-js) for [Deno](https://deno.land/) and [azure-functions-deno-worker](https://github.com/anthonychu/azure-functions-deno-worker).

In the development, I found the following:

- Handling return value from an orchestrator function is needed to make Durable Functions work when `yield` is used in the function.
- In the case of built-in workers (Node.js), the functions host always handles the return value from the orchestrator function even though there is no `$return` binding definition in function.json for the function, as the following example.

```json
"bindings": [
{
"name": "context",
"type": "orchestrationTrigger",
"direction": "in"
}
]
```

The code is at this line.
https://github.com/Azure/azure-functions-host/blob/8596a27c5a3cf1c26546418fe8ac6bcf132f808b/src/WebJobs.Script.Grpc/Channel/GrpcWorkerChannel.cs#L577-L582

Meanwhile, in the case of Custom Handler, if there is no `$return` binding definition in function.json, the return value from the orchestrator function is ignored even though proper value returns from the function by using [`ReturnValue`](https://docs.microsoft.com/en-us/azure/azure-functions/functions-custom-handlers#response-payload).
According to this line, it is needed that both the return value and the `$return` binding definition are not `null`.

https://github.com/Azure/azure-functions-host/blob/8596a27c5a3cf1c26546418fe8ac6bcf132f808b/src/WebJobs.Script/Workers/Http/HttpScriptInvocationResultExtensions.cs#L31-L38

To make the function host handle the return value, I tried some `$return` binding definitions like the following binding definition, but I cannot find right binding definition to do that.

```json
"bindings": [
{
"name": "context",
"type": "orchestrationTrigger",
"direction": "in"
},
{
"type": "http", // or blank ""
"name": "$return",
"direction": "out"
}
]
```

#### Describe the solution you'd like
Could you please consider that the function host handles the return value from the function like the following example (which I confirmed) [at this line](https://github.com/Azure/azure-functions-host/blob/8596a27c5a3cf1c26546418fe8ac6bcf132f808b/src/WebJobs.Script/Workers/Http/HttpScriptInvocationResultExtensions.cs#L31-L38) if there is no way to return the value properly in order to work the orchestrator function in the custom handler?

```csharp
if (httpScriptInvocationResult.ReturnValue != null)
{
BindingMetadata returnParameterBindingMetadata = GetBindingMetadata(ScriptConstants.SystemReturnParameterBindingName, scriptInvocationContext);
if (returnParameterBindingMetadata != null)
{
scriptInvocationResult.Return = GetBindingValue(returnParameterBindingMetadata.DataType, httpScriptInvocationResult.ReturnValue);
}
// This is additional codes for Durable Function of custom handler
else
{
scriptInvocationResult.Return = GetBindingValue(DataType.String, httpScriptInvocationResult.ReturnValue);
}
}
```

#### Describe alternatives you've considered
n/a

#### Additional context
n/a

Contributor guide

Open the contributing guide

Research direction

Start with src/WebJobs.Script.Grpc/Channel/GrpcWorkerChannel.cs and src/WebJobs.Script/Workers/Http/HttpScriptInvocationResultExtensions.cs, following the linked sections that process orchestrator and custom-handler return values. Compare the built-in worker path with the $return binding check, then determine and verify the intended behavior when that binding is absent.

Written by the indexing model from the issue text.

Assessment

Tech stack
azure, csharp
Domain
backend, cloud
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.