wil-shiftinsert
03/19/2022, 11:45 AMquick
based service is not ready yet on my reinit request.
A work around would be easy but I was wondering: are coldbox modules ready when preProcess is fired for the first time?bdw429s
03/20/2022, 3:18 AMbdw429s
03/20/2022, 3:19 AMwil-shiftinsert
03/20/2022, 2:07 PMThe function [newEntity] does not exist in the Object.
This is interesting because it is a quick service which should always have this method. Probably is is just trying a provider.
The error is only happening in my reinit call. If I try again a second time, most of the time there will not be an error. If I try to reinit from an authenticated user I will get an error, if I try to reinitialize from an unauthenticad user no errors.
modules/quick/models/BaseService.cfc in onMissingMethod at line 55
public any function onMissingMethod( required string missingMethodName, struct missingMethodArguments = {} ) {
return invoke(
variables.entity.newEntity(),
missingMethodName,
missingMethodArguments
models/auth/UserService2.cfc
in retrieveUserById
at line 202
modules/cbsecurity/modules/cbauth/models/AuthenticationService.cfc
in getUser
at line 163
coldbox/system/ioc/Provider.cfc
in onMissingMethod
at line 110
models/utils/SecurityProxy.cfc
in getUsername
at line 41
coldbox/system/ioc/Provider.cfc
in onMissingMethod
at line 110
interceptors/PrepareRcInterceptor.cfc
in preProcess
at line 30
My interceptor is calling some securityproxy which has an injected cbauth service. I am calling
return auth.isLoggedIn() ? auth.getUser().getId() : "--none--";
here and auth.isLoggedIn is just a call to
return variables.sessionStorage.exists( variables.USER_ID_KEY );
I guess the sessionstorage is not cleared yet, because the reinit call has not finished yet. Because it is not cleared yet it is trying to get a user in the middle of a reinit, which leads to unreliable results and errors. I just shouldn’t ask for some user state in the middle of a reinit, but it happens in ALL requests because this is a onPreProcess interception.
Since I only want to know a username and id or return some default value if there’s no authenticated user yet I wrapped these calls in a try catch now and return the defaults there. I could also protect this block of code by checking for a reinit key and return the defaults.
Problem solved for now. Reinit on production is tricky. Most of the time we just restart the whole lucee server on a new deployment, but this is a system with multiple apps