Deployed Cloud Code Issue

My team and I have come across a strange issue. We have spent a lot of time looking at it and have had no luck. Any help would be greatly appreciated.

Issue: Our debug code works properly but our identical deployed code does not work with the same behavior.

When we run our cloud code API in debug, our service (called registerUser) works properly (it creates a user and a ‘member’ object). When have then directly deployed that same source code using ‘npm run deploy’ and it does so successfully. We even have checked to see if all the code matches and it does. We are running the correct API call and we haven’t found a similar issue from other calls.

Really strange bug, at this point we are hoping it is internal to Backendless so we can get the call working before our deadline.

Our APP ID is DD9FC30D-3A6F-AB4C-FF9C-24DC92E73100

Service Name: UserService
Method/ API Call: registerUser

Some test data that should work:

{
    "firstName": "John",
    "lastName": "Doe",
    "phone": "1230001234",
    "email": "string@mail.com",
    "profilePic": "none",
    "churchId": 38,
    "build": 0
}

If you need to run multiple calls, the only field that must be unique in the database is ‘phone’. You should be able to keep the other fields the same without any issues.

if helpful, firstname and lastname can be any non-empty string, phone can be any 10-digit string of numbers that does not already exist in the database, and email can be changed to any version of an email format string@string.string, profile pic can be any string, church ID needs to match a church ID in the database (39, 40, 41,42 are currently valid), and build must be 0

OBSERVED BEHAVIOR:

When running debug, registerUser creates a User object and an object in the ‘members’ table. When running the deployed version of the same code, only the User is created. No member object is made.

The intended result is the deployed interface will behave like the debug interface. Such that the deployed version will add a member and a user object.

Hi @Noah_Caldwell

I believe the issue with missing async/await, take a look at the following comment:

1 Like

Thanks that information did lead to us resolving this bug.

For those who may visit this post in the future because of a similar problem, here is the solution. We had a function that returned a promise but before the return statement, we had another function that used a promise as well. Because the prior promise was not yet resolved when the next promise was returned, the first promise was not running.

Therefore all we had to do is resolve the first promise. In our case, we just added an await keyword in front of the async function in order to resolve the promise before moving to the return statement.

So here is a basic example:

function api_call(arg) {
  var query_builder = setup_query(arg);
  async_function(); // async promise function
  return Backendless.Data.of("table").findFirst(query_builder) // also async function
}

Since async_function() is not resolved when we return the data object, Backendless never finishes running async_function(). Therefore you must resolve that function. You can add an await to make the function act synchronously, but there are other ways as well.

async function api_call(arg) {
  var query_builder = setup_query(arg);
  await async_function(); // async promise function
  return Backendless.Data.of("table").findFirst(query_builder) // also async function
}

I’m not a javascript expert so if someone wants to explain or correct that solution, please do.

1 Like

I was wondering if anyone knew why this would cause the original code to work in debug as opposed to not working when deployed. I understand the error, but what about the deployed code makes the outcome different?

when you run your code in debug the system doesn’t kill a process worker when it’s done, but on the cloud server it kills the process worker right after when a task was processed

https://backendless.com/docs/bl-js/bl_troubleshooting.html#servercode-works-well-in-the-debug-mode-but-does-not-when-deployed-to-the-cloud