2

I have a FW/1 app on Railo 4.2.2/Apache and for some reason it's calling onApplicationStart on every request. I can tell it's not any reinit code - put in a callStackGet() dump in setupApplication and can see that the root call is onApplicationStart (not via any init hook). Are there any known bugs in Railo that would cause this? I've double checked the application timeout (1 day) and the FW/1 setting - it's turned off - so there should be no reason the app would be losing application scope on every request.

There is another strange thing I'm seeing too, but I don't know that it is related. In setup application I am creating a new user object (via ORM) and persisting it if a local admin doesn't exist. I dump it and see the ID, but it's not in the database when I query the table (yes, I flushed it). The next page hit creates the user again (since it doesn't exist still...).

Edit: Add persist object code for Adam.

function setupApplication() {
    // bean factory should look in the model tree for services and beans
    var bf = new framework.ioc( "/com/sharp/model" );
    setBeanFactory( bf );
    ormReload();

    if( getEnvironment() == 'dev' ){
        writeLog('Checking for dev user');
        if( !arrayLen( ormExecuteQuery('from User where username = ?', ['admin']) ) ){
            var user = new com.sharp.model.user.User({username: 'admin', password: hash('p@ssw3rd'), isAdmin: true});
            entitySave( user );
            ormFlush();
            writeDump(user);
            writeDump(callStackGet());
            writeLog('User admin created')
        }
        else{
            var user = bf.getBean('userService').getByUsername('admin');
            writeLog('Dev admin user already exists.  Done.')
        }
        var auth = bf.getBean('userService').authenticate( 'admin', 'p@ssw3rd' );
    }

}
user3071284
  • 6,955
  • 6
  • 43
  • 57
Todd Sharp
  • 3,207
  • 2
  • 19
  • 27
  • Are you setting the application name? – Bernhard Döbler Dec 07 '14 at 00:06
  • 2
    Agreed with Bardware, if you're not setting an application name or are setting it to something random every time, that could cause this behavior. – Adam Tuttle Dec 07 '14 at 00:19
  • As for your ORM user creation bug, post the code man. – Adam Tuttle Dec 07 '14 at 00:20
  • Application name is set, yes. And no, there is no duplicate application running locally. @AdamTuttle - come on man, you know I know how to create and persist a simple user ;) – Todd Sharp Dec 07 '14 at 00:37
  • I would usually give you the benefit of the doubt, true. But if you don't want to post code, how can you expect help? Anyway, to identify if it's some sort of bug with creating entities in onApplicationStart (which is calling FW/1's setupApplication), try moving the same code into index.cfm or something. Double check that it's not your persistence code. Think like a scientist and isolate those variables. – Adam Tuttle Dec 07 '14 at 00:45
  • Code added. Typing nonsense to get to min chars... – Todd Sharp Dec 07 '14 at 01:24
  • FWIW - I had this working swimmingly on ACF 10 a few days ago. – Todd Sharp Dec 07 '14 at 01:24
  • OK, so, the application reload issue is not happening anymore. I had wondered if there was something stuck in the template cache somehow that was causing that issue and I'm guessing that was what it was. So, get this. The user is persisted, if I do an ormExecuteQuery it returns the record, BUT - when I query the table in MySQL workbench I get no records (I triple checked that I'm in the correct schema). – Todd Sharp Dec 07 '14 at 01:30
  • Doubt it affects your results, but out of curiosity why aren't you doing the initial admin lookup conditional with `bf.getBean('userService').getByUsername('admin')`? I don't see any red flags in your code; but then I don't put ORM creates into onApplicationStart. Did you try moving that out to a view file just to isolate the code from the event? Try to determine what combination is causing it: Railo+Application.cfc+ORM? Railo+FW/1+ORM? Railo+Application.cfc+FW/1+ORM? Also might be useful to share your `this.ormSettings` config. – Adam Tuttle Dec 07 '14 at 03:09
  • It's throwaway code, just figured it should work. – Todd Sharp Dec 07 '14 at 03:59
  • It sounds like you might want to look in FW/1 and find all the things that can fire off `onApplicationStart`. There can't be that many – James A Mohler Dec 07 '14 at 20:19
  • What are your ORM settings? Have you tried wrapping the new/save/flush code in a `transaction{}`? – CfSimplicity Dec 10 '14 at 10:24

1 Answers1

0

I think the failure to persist to the DB may be a regression bug with Railo 4.2.2. See https://issues.jboss.org/browse/RAILO-3279

Try wrapping your save/flush in a transaction:

transaction{
    entitySave( user );
    ormFlush();
}

Normally you shouldn't need both. Either the transaction or ormFlush should make it persist.

CfSimplicity
  • 2,338
  • 15
  • 17