milk enjoyer
milk enjoyer12mo ago

Connection lost while action was in flight when using node "https"

I am using it within a "use node" actions file, but it does not work.
19 Replies
milk enjoyer
milk enjoyerOP12mo ago
The error is: Connection lost while action was in flight I specifically need https.get to work, I have been trying all different ways but to no avail on further investigation, i realized that not only does https.get not work, fetch also behaves strangely compared to fetch in other node environments.
Michal Srb
Michal Srb12mo ago
@milk enjoyer can you provide more details about how the fetch in our Node environment differs from what you're expecting?
milk enjoyer
milk enjoyerOP12mo ago
@Michal Srb I got it to work now after troubleshooting with @lee , it turns out the problem was because the IP address of convex actions change every time because it is a new lambda instance
jeff
jeff10mo ago
Having this issue now. What was the solution? How does even changing IPs cause issues doing a GET? 🤔 I use 2 API calls: client.hostedCheckout.createHostedCheckout works with no issues. client.hostedCheckout.getHostedCheckout fails without exception. All the in-browser function execution tool says is exactly Connection lost while action was in flight. Wrapping the API call in a try/catch black has no effect. No output (even static, on line 1 of the action handler) is printed when that API call is called anywhere in the action. (@james you're online :p ) I honestly have no clue how to debug this further. There's flat out zero results when googling for the error message in quotes 🤷‍♂️ (@milk enjoyer not sure you get notifications about this. Any more you remember? 🤔 Thanks! ❤️ ) I dug into the node_modules/ structure now. The difference between the two methods is minimal... getHostedCheckout:
/* This file was auto-generated. */
const communicator = require('../../utils/communicator');

module.exports = (sdkContext) => {
return function (merchantId, hostedCheckoutId, paymentContext, cb = null) {
communicator.json(
{
method: 'GET',
modulePath: `/v2/${merchantId}/hostedcheckouts/${hostedCheckoutId}`,
body: null,
paymentContext,
cb,
},
sdkContext
);
};
};
/* This file was auto-generated. */
const communicator = require('../../utils/communicator');

module.exports = (sdkContext) => {
return function (merchantId, hostedCheckoutId, paymentContext, cb = null) {
communicator.json(
{
method: 'GET',
modulePath: `/v2/${merchantId}/hostedcheckouts/${hostedCheckoutId}`,
body: null,
paymentContext,
cb,
},
sdkContext
);
};
};
versus createHostedCheckout:
/* This file was auto-generated. */
const communicator = require('../../utils/communicator');
const requestSchema = require('../../schemas/CreateHostedCheckoutRequest.json');
const validator = require('../../utils/validator');

module.exports = (sdkContext) => {
return function (merchantId, postData, paymentContext, cb = null) {
// validate postData
validator.validatePostData(postData, requestSchema, sdkContext);

communicator.json(
{
method: 'POST',
modulePath: `/v2/${merchantId}/hostedcheckouts`,
body: postData,
paymentContext,
cb,
},
sdkContext
);
};
};
/* This file was auto-generated. */
const communicator = require('../../utils/communicator');
const requestSchema = require('../../schemas/CreateHostedCheckoutRequest.json');
const validator = require('../../utils/validator');

module.exports = (sdkContext) => {
return function (merchantId, postData, paymentContext, cb = null) {
// validate postData
validator.validatePostData(postData, requestSchema, sdkContext);

communicator.json(
{
method: 'POST',
modulePath: `/v2/${merchantId}/hostedcheckouts`,
body: postData,
paymentContext,
cb,
},
sdkContext
);
};
};
The action also runs for >1000ms.
james
james10mo ago
@jeff I’m on my phone rn so can’t debug immediately but it sounds like the errors you’re seeing are being reported client side due to a failed request. Can you post the server side error listed in the logs page of the convex dashboard? Feel free to also post your instance name and we can check error logs
jeff
jeff10mo ago
Thanks, James! Appreciate the help (am totally blocked!)
jeff
jeff10mo ago
Just to clarify, there isn't really a client-side involved... I an testing using the in-browser Run Function utility
No description
jeff
jeff10mo ago
and there's no logs in Logs at all
No description
jeff
jeff10mo ago
hence why I am totally stuck 🙈 I put a 10 second sleep after a static console.log (and a process.stdout.write and a process.stderr.write) and before the problematic API call; nop output. So it can't be a race condition (and I think not a flushing thing either but unsure)...
ballingt
ballingt10mo ago
@jeff just to eliminate the browser aspect, could you try running this from the command line? with npx convex run payment:verifyPayment '{"returnMAC": "INSERT HERE", "hostedCheckoutId": "INSERT HERE"}' I'll try to repro with something similar
jeff
jeff10mo ago
straight away
jeff@DESKTOP-FUM4FMP:~/repos/RocketMarket$ npx convex run payment:verifyPayment '{"returnMAC": "INSERT HERE", "hostedCheckoutId": "INSERT HERE"}'
✖ Failed to run function "payment:verifyPayment":
Error: {"code":"InternalServerError","message":"Your request couldn't be completed. Try again later."}
jeff@DESKTOP-FUM4FMP:~/repos/RocketMarket$ npx convex run payment:verifyPayment '{"returnMAC": "INSERT HERE", "hostedCheckoutId": "INSERT HERE"}'
✖ Failed to run function "payment:verifyPayment":
Error: {"code":"InternalServerError","message":"Your request couldn't be completed. Try again later."}
(N.B.: Yes I left the strings INSERT HERE in place because I've already hardcoded everything out of desperation XD.)
ballingt
ballingt10mo ago
Thanks, that narrows it down. What's the instance name so I can check server-side logs?
jeff
jeff10mo ago
something with an animal, and an adjective to describe it... lemme look it up 😛
ballingt
ballingt10mo ago
You can send it privately if proper security isn't set up yet (once someone knowns this they can make calls to your application)
jeff
jeff10mo ago
(except for internal{Action/Querie/Mutation}s right?)
ballingt
ballingt10mo ago
One thing I see (and we have an in-progress project to address this) is an error
Unhandled lambda error: Unhandled. Payload: {
"errorType": "TypeError",
"errorMessage": "cb is not a function",
"trace": [
"Error",
" at convex:/user/payment.js:7830:13",
" at emit (node:events:529:35)",
" at endReadableNT (node:internal/streams/readable:1400:12)",
" at processTicksAndRejections (node:internal/process/task_queues:82:21)"
]
}
Unhandled lambda error: Unhandled. Payload: {
"errorType": "TypeError",
"errorMessage": "cb is not a function",
"trace": [
"Error",
" at convex:/user/payment.js:7830:13",
" at emit (node:events:529:35)",
" at endReadableNT (node:internal/streams/readable:1400:12)",
" at processTicksAndRejections (node:internal/process/task_queues:82:21)"
]
}
that we should be surfacing. Based on the code you posted the difference between these two doesn't make much sense, they both might be passing null to cb! What library is this? This particular problem was solved in DMs, this particular issue was solved by passing another argument,null — but looks like we have an issue with crashing too hard and reporting stack traces in some situations in Node.js. We'll report when we've addressed this.
jeff
jeff10mo ago
The fix, on my end, in the end was to explicitly pass some null parameterm as I had done on the working API call also: const createHostedCheckoutResponse = await client.hostedCheckout.createHostedCheckout(WORLDLINE_PSPID, createHostedCheckoutRequest, null); versus hostedCheckoutStatus = await client.hostedCheckout.getHostedCheckout(WORLDLINE_PSPID, args.hostedCheckoutId); which now became: hostedCheckoutStatus = await client.hostedCheckout.getHostedCheckout(WORLDLINE_PSPID, args.hostedCheckoutId, null);
james
james10mo ago
Thanks for jumping in Tom. Yeah we’re actively working on surfacing error messages more clearly.
jeff
jeff10mo ago
"crashing too hard" also explains why even my try/catch was fruitless :p Yeah, thanks again Tom—really appreciate it, guys!! ❤️

Did you find this page helpful?