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

Cannot read properties of undefined (reading 'type') #210

Closed
GravlLift opened this issue Jan 22, 2024 · 4 comments · Fixed by #216
Closed

Cannot read properties of undefined (reading 'type') #210

GravlLift opened this issue Jan 22, 2024 · 4 comments · Fixed by #216
Assignees
Labels
bug Something isn't working
Milestone

Comments

@GravlLift
Copy link

GravlLift commented Jan 22, 2024

Investigative information

Please provide the following:

  • Timestamp: 2024-01-22T22:14:28.4980344Z
  • Function App name: AZUD-RMS-FA-01
  • Function name(s) (as appropriate): customerLookup
  • Invocation ID: 3325acd5-1aad-4923-bffc-0a6fbfe52204
  • Region: East US 2

Repro steps

Provide the steps required to reproduce the problem:

  1. Open https://azud-rms-fa-01.azurewebsites.net/api/v4/customer?emailAddress=lightspeed.e2e%40gmail.com in a browser

Expected behavior

Provide a description of the expected behavior.

Http request should return valid JSON and 200 response

Actual behavior

500 error

Related information

Provide any related information

  • Programming language used: javascript
  • Bindings used:
app.get("customerLookup", {
  authLevel: "anonymous",
  route: `api/v{version:int:min(4):max(${currentMajorVersion})}/customer`,
  handler,
});
  • Stack Trace:
Stack: TypeError: Cannot read properties of undefined (reading 'type')
    at InvocationModel.<anonymous> (/node_modules/@azure/functions/dist/webpack:/@azure/functions/src/InvocationModel.ts:65:63)
    at Generator.next (<anonymous>)
    at <anonymous> (/node_modules/@azure/functions/dist/webpack:/@azure/functions/src/InvocationContext.ts:96:10)
    at new Promise (<anonymous>)
    at __webpack_modules__../src/InvocationModel.ts.__awaiter (/node_modules/@azure/functions/dist/webpack:/@azure/functions/src/InvocationContext.ts:96:10)
    at InvocationModel.getArguments (/node_modules/@azure/functions/dist/webpack:/@azure/functions/src/InvocationModel.ts:46:23)
    at y.<anonymous> (/azure-functions-host/workers/node/dist/src/worker-bundle.js:2:37611)
    at Generator.next (<anonymous>)
    at o (/azure-functions-host/workers/node/dist/src/worker-bundle.js:2:35629)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5) 

This error is not reproducible locally, only on our Azure instance. While it is reproducible for a single function run, restarting the function will fix the issue.

Relevant code appears to be here:

async getArguments(): Promise<InvocationArguments> {
const req = this.#coreCtx.request;
const context = new InvocationContext({
invocationId: nonNullProp(this.#coreCtx, 'invocationId'),
functionName: this.#functionName,
logHandler: (level: RpcLogLevel, ...args: unknown[]) => this.#userLog(level, ...args),
retryContext: fromRpcRetryContext(req.retryContext),
traceContext: fromRpcTraceContext(req.traceContext),
triggerMetadata: fromRpcTriggerMetadata(req.triggerMetadata, this.#triggerType),
options: fromRpcBindings(this.#bindings),
});
const inputs: unknown[] = [];
if (req.inputData) {
for (const binding of req.inputData) {
const bindingName = nonNullProp(binding, 'name');
let input: unknown = fromRpcTypedData(binding.data);
const bindingType = this.#bindings[bindingName].type;
if (isTimerTrigger(bindingType)) {
input = toCamelCaseValue(input);
}
if (isTrigger(bindingType)) {
inputs.push(input);
} else {
context.extraInputs.set(bindingName, input);
}
}
}
return { context, inputs };
}

@ejizba
Copy link
Contributor

ejizba commented Jan 24, 2024

Hi @GravlLift I'm not sure what could be causing this, but my best guess is it's some sort of race condition that only happens with more complex projects. It'll be hard for me to repro, so it would be helpful if we could get more logs. Could you replace line 203 in node_modules/@azure/functions/dist/azure-functions.js which should look like this:

const bindingType = __classPrivateFieldGet(this, _InvocationModel_bindings, "f")[bindingName].type;

With this code:

let bindingType;
try {
    bindingType = __classPrivateFieldGet(this, _InvocationModel_bindings, "f")[bindingName].type;
} catch (err) {
    context.log(`bindingName: ${bindingName}`);
    context.log(`inputData: ${JSON.stringify(req.inputData.map((id) => id.name))}`);
    context.log(`bindings: ${JSON.stringify(__classPrivateFieldGet(this, _InvocationModel_bindings, "f"))}`);
    throw err;
}

And then share the new logs with us if/when you get the error to reproduce again.

@sga-solita
Copy link

sga-solita commented Jan 26, 2024

We are getting this error as well, in a timer triggered function:

Exception while executing function: Functions.NameOfTimerTrigger Result: Failure
Exception: Cannot read properties of undefined (reading 'type')
Stack: TypeError: Cannot read properties of undefined (reading 'type')
    at InvocationModel.<anonymous> (/home/site/wwwroot/node_modules/@azure/functions/dist/azure-functions.js:203:114)
    at Generator.next (<anonymous>)
    at /home/site/wwwroot/node_modules/@azure/functions/dist/azure-functions.js:142:71
    at new Promise (<anonymous>)
    at __webpack_modules__../src/InvocationModel.ts.__awaiter (/home/site/wwwroot/node_modules/@azure/functions/dist/azure-functions.js:138:12)
    at InvocationModel.getArguments (/home/site/wwwroot/node_modules/@azure/functions/dist/azure-functions.js:187:16)
    at y.<anonymous> (/azure-functions-host/workers/node/dist/src/worker-bundle.js:2:37611)
    at Generator.next (<anonymous>)
    at o (/azure-functions-host/workers/node/dist/src/worker-bundle.js:2:35629)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)

When I look in the logs, it seems to start happening at midnight, and then a restart resolves it. Then next midnight it starts happening again. Although that could be because we have multiple other functions starting at that time, but Im not sure.

@GravlLift
Copy link
Author

@ejizba, took a while for it to reappear, but here it is:

bindingName: httpTrigger17
inputData: ["httpTrigger17"]
bindings: {"httpTrigger19":{"authLevel":"anonymous","route":"api/v3/shipments","methods":["GET"],"type":"httpTrigger","name":"httpTrigger19","direction":"in"},"$return":{"type":"http","name":"httpOutput19","direction":"out"}}

The route seen under bindings is the one that crashed when this was logged.

@ejizba ejizba added this to the February 2024 milestone Feb 3, 2024
@ejizba ejizba added the bug Something isn't working label Feb 3, 2024
@ejizba ejizba self-assigned this Feb 3, 2024
@ejizba
Copy link
Contributor

ejizba commented Feb 5, 2024

@GravlLift thanks for the info! I just merged a change that I'm pretty confident will fix this, although it's hard to reproduce the bug so I can't be 100% sure. The change will be included in the next release towards the end of February, although you can try it out earlier following these instructions: https://github.com/Azure/azure-functions-nodejs-library/wiki/Install-Insiders-Build

If you do try it out, let us know if it works or not! Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants