As of April 12th, you must go to Progress SupportLink to create new support cases or to access existing cases. Please, bookmark the SupportLink URL and use the new portal to contact the support team.
I have a collection hook that is failing with the following output:
"The Business Logic script violated a constraint. See debug message for details." UserInfo=0xcf72b80 {NSLocalizedDescription=The Business Logic script violated a constraint. See debug message for details., kinveyRequestId=0c842aafa7334f0895064e212e6e7b46, kinveyInternalErrorString=Blocked, reason: response.complete() or response.continue() was called multiple times, remaining time: 2871
I took a look on my code and there is only one line for response.continue. So, is there anything wrong?
I THINK your issue is due to the response.continue() location. It comes AFTER your call to findUser. findUser relies on the asynchronous collectionAccess calls to the MongoDB.
What will happen :
* The findUser method will BEGIN
* The response.continue will happen immediately and not wait for the findUser to complete.
You need to move the response.continue() into your callback. This will delay the response.continue() until after the DB query is completed. Something like this should do the trick.
So, do I need to move the response.continue to inside de callback even if my code is asynchronous?
I ask because my intention was:
[parallel]
- Start process to find user, then save info um users collection
- response.continue
[/parallel]
I though if I called response.continue just after the findUser, it wouldn't cancel the findUser process since it's an async call to the mongoDB.
J
Justin Noel
said
almost 10 years ago
Neto,
I apologize. I didn't read what your code was actually doing. I was assuming it was going to use the found info to add to the response. That's why I felt you needed the response.continue() inside the callback.
Honestly, I don't know how the Kinvey backend would deal with your intention of :
* onPostSave - find a user and modify it
* respond with response.continue() to the initial request in parallel
I don't know if the response.continue() will cause the thread to cancel or not even if the findUser function has not finished. However, I believe it WILL.
Kinvey will need to provide a definitive answer to this.
M
Michael
said
almost 10 years ago
Just to answer a couple of the questions here
The blocking violation can be the result of any business logic code that is executed for your app that violates the constraint. So you may have another collection hook or endpoint that is violating the constraint and causing your app to be temporarily blacklisted since this can cause bad script behavior and is vital for maintaining the sandbox.
As far as your asynchronous threads, they will continue to exist even with a response.continue() up to the 2 second timeout, and then they will be terminated. response.continue() and response.complete() do not explicitly terminate asynchronous threads, although response.error() does. Still, unless there is a need to immediately return to the client, it is best practice to put your response.complete() in the callback completion block, because otherwise the call may return an error that will never be processed.
I
Igor
said
almost 10 years ago
Michael,
Could you clarify the blocking mechanism?
- does one faulty script cause all BL to be blacklited for 1 hour?
- can I use 'remaining time' to avoid retrying endlessly?
To temporarly deactivate a collection hook, I've put a response.continue(); as the first line:
function onPreSave(request, response, modules) {
response.continue();
}
and I got on the blacklist! How can you bypass a BL?
M
Michael
said
almost 10 years ago
Igor -
It is not one faulty script - it is a threshold of executions occurring in a limited time window. So, for example, if your bad BL script is called once per hour and has the bad behavior, you likely won't get blacklisted. But if it's called every second, you likely will.
The script that just contains response.continue() will not add you to the blacklist.
N
Neto Leal
said
almost 10 years ago
Hi Michael, in this case I'm worried about another collection hook of mine. Can you help me to review my code?
My app is about to get released and I can't let it get blacklisted. If yes, I can post the code here or privately via email.
Neto Leal
"The Business Logic script violated a constraint. See debug message for details." UserInfo=0xcf72b80 {NSLocalizedDescription=The Business Logic script violated a constraint. See debug message for details., kinveyRequestId=0c842aafa7334f0895064e212e6e7b46, kinveyInternalErrorString=Blocked, reason: response.complete() or response.continue() was called multiple times, remaining time: 2871
I took a look on my code and there is only one line for response.continue. So, is there anything wrong?
This is my code:
function onPostSave(request, response, modules){
var collectionAccess = modules.collectionAccess
, userCollection = collectionAccess.collection('user')
, trackings = collectionAccess.collection( "Tracking" )
, utils = modules.utils
, push = modules.push
, logger = modules.logger;
var findUser = function( id, callback )
{
userCollection.findOne( { "_id": userCollection.objectID( id ) }, function( error, foundUser ){
if( !error )
{
if( callback ) callback( foundUser );
}
else
{
logger.error( request.method + ": Error finding user: " + error );
if( callback) callback( null );
}
});
};
findUser( request.body.user._id, function( user ){
user[ "_geoloc" ] = request.body._geoloc;
user[ "_geoDateTime" ] = new Date( );
userCollection.update( { "_id": userCollection.objectID( request.body.user._id ) }, user );
logger.info( user.username + " tracked @ " + request.body._geoloc[ 1 ] + ", " + request.body._geoloc[ 0 ] );
});
response.continue( );
}