You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Saving model with auto-fetched relations causes stack overflow #279
@goulwenlorcy would you be able to test with v2.0.15 of ORM and tell us whether it has the same issue there? Just trying to narrow down where the issue may have crept in.
.. was added by me to try to solve the double call to .save(). Not sure how it happened. It makes the workflow continue if there are no changes (avoiding calling UPDATE on the model but continue to check associations).
app.use(orm.express(Config.db.uri,{define: function(db,models){models.User=db.define("users",{email: String});models.Post=db.define("posts",{context: String},{// If I comment out this line it worksautoFetch: true});models.Post.hasOne("user",models.User);models.Post.get(1337,function(e,p){// If I uncomment this line it works// p.user = null;p.save({updated_at: newDate()},function(err){console.log('done')});});}}));
Just a heads up - the test runner is currently not running test. I've fixed it in my repo (2e50cf2) which I'm planning on merging as soon as I can get a free minute to make Travis pass all tests. (Having issues with the SQLite driver, but ORM itself is working correctly)
Looks like it may be caused by a race condition in saveAssociations. The assumption is made that all the loops which begin async operations to save associations (if any) will complete before the async operations do. The result is that pending === 0 can hold in as many as 3 places.
I'm going to try and fix the issue quickly and I'll let you know how it turns out.
Okay, the issue can be fixed by doing the following:
Initialize pending = 1 at Instance.js:225
Test if(--pending === 0) at Instance.js:289
Rationale
Treat the pending completion of loops as a pending operation, and only allow us to complete once the loops have finished AND all async operations have completed.
Activity
dresende commentedon Aug 3, 2013
Please tell use node version, orm version.
dirkmc commentedon Aug 3, 2013
This is with the latest version of orm on the master branch
dirkmc commentedon Aug 4, 2013
In Instance.js I added some debugging output so that it looks like this:
Is this line correct?
This is the console output:
In my definitions I have this:
goulwenlorcy commentedon Aug 7, 2013
Hello, I have the same problem with a simple code (latest version of orm & node v0.8.9)
Node crash with:
Without autoFetch, it works.
notheotherben commentedon Aug 7, 2013
@goulwenlorcy would you be able to test with v2.0.15 of ORM and tell us whether it has the same issue there? Just trying to narrow down where the issue may have crept in.
goulwenlorcy commentedon Aug 7, 2013
With the v2.0.15, I haven't the crash error but it doesn't work and the /* ... */ part is executed 2 times.
dresende commentedon Aug 7, 2013
This line (and subsequent scope)..
.. was added by me to try to solve the double call to
.save(). Not sure how it happened. It makes the workflow continue if there are no changes (avoiding callingUPDATEon the model but continue to check associations).dresende commentedon Aug 7, 2013
@goulwenlorcy please post a complete example. I cannot reproduce your error..
dirkmc commentedon Aug 7, 2013
Here's a complete example:
This produces a stack overflow error:
dresende commentedon Aug 11, 2013
Please try v2.1.0 and tell us if the same happens.
petrovi4 commentedon Aug 12, 2013
I have same bug in v2.1.0
dirkmc commentedon Aug 12, 2013
Hi, I'm afraid I see the same bug also. Diogo are you not able to repro with the code I pasted above?
dxg commentedon Aug 12, 2013
I've reproduced it, going to add a failing test case in a moment
notheotherben commentedon Aug 12, 2013
Just a heads up - the test runner is currently not running test. I've fixed it in my repo (2e50cf2) which I'm planning on merging as soon as I can get a free minute to make Travis pass all tests. (Having issues with the SQLite driver, but ORM itself is working correctly)
Infinite loop test case - issue #279
21 remaining items
notheotherben commentedon Aug 13, 2013
Stack Traces
First Call to Callback
setup.validations.stalkIdsaveInstanceExtraafterSavesaveInstancesaveAssociationsaveInstanceExtrasaveInstanceSTARTnextHooknextHookexport.waitSecond Call to Callback
setup.validations.stalkIdsaveInstanceExtraafterSavesaveInstancesaveAssociationssaveInstanceSTARTnextHooknextHookexport.waitnextHookBreakdown:
saveInstance -> saveInstanceExtra -> saveAssociation -> saveInstance -> afterSave -> saveInstanceExtrasaveInstance -> saveAssociations -> saveInstance -> afterSave -> saveInstanceExtranotheotherben commentedon Aug 13, 2013
Looks like it may be caused by a race condition in
saveAssociations. The assumption is made that all the loops which begin async operations to save associations (if any) will complete before the async operations do. The result is thatpending === 0can hold in as many as 3 places.I'm going to try and fix the issue quickly and I'll let you know how it turns out.
notheotherben commentedon Aug 13, 2013
Okay, the issue can be fixed by doing the following:
Initialize
pending = 1at Instance.js:225Test
if(--pending === 0)at Instance.js:289Rationale
Treat the pending completion of loops as a pending operation, and only allow us to complete once the loops have finished AND all async operations have completed.
Fix infinite loop in save (dresende#279)
dirkmc commentedon Aug 13, 2013
Works for me
dxg commentedon Aug 13, 2013
Hahaha yeah that's where I was at yesterday before I went to sleep.
We need to add a test case for 8f8e2db .
On a side note, some of that saving code needs a refactor.
Note the similarity between lib/Instance.js#L121 and /lib/Instance.js#L217.
It's effectively a duplicate (
nextisafterSave). I have some WIP changes to fix this, but will wait till all your stuff is merged.dresende commentedon Aug 14, 2013
Yes, the difference is that line 217 is run after the
db.updatethat it's what is being avoided by that (because there's nothing to save).dirkmc commentedon Aug 14, 2013
While you guys are refactoring that code, would it be possible to take a look at this:
#278
dresende commentedon Aug 14, 2013
Don't worry, we'll look into it before posting a new version 😄
dirkmc commentedon Aug 14, 2013
Great, thanks!
petrovi4 commentedon Aug 14, 2013
Stack overflow fixed in current master, but other bug still exists:
After run this code:
I see in console:
So, second save always override changes made with first.
p.s. With cache enabled after
property tour.tourist still contains previous list of tourists.
SamuelBolduc commentedon Aug 14, 2013
Looks like I'm having the same issue here #298
dresende commentedon Aug 20, 2013
This should be fixed now. About this other issue of multiple
INSERTlet's discuss it in #298 .Gromina commentedon Sep 16, 2013
I still have stack overflow problem on save in 2.1.1:
When I save Thing instance, it gives me stack overflow. What's wrong with my code?
Upd: I've made a fork with failing test #338