-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
requireUser sometimes hangs #22
Comments
@mxab I tried to test this issue and it all seems fine for me. I tested it using angular-meteor-whatsapp project, I used |
it is really hard to reproduce it as we experience it randomly. I will try to replace it with awaitUser. Out of curiosity, the afterFlush seems very intentional in the requireUser part. I assume I should also do a Tracker.afterFlush then? |
The |
Hmm I swtiched everything to await, but sill I have this random not finishing issue. This is the peace of code that currently is the problem
Quite often but so far random I see which does not make any sense to me |
Hmm I can't seem to reproduce your problem, everything works fine for me. Make sure you actually login before invoking |
@DAB0mB I'm working on the same project with @mxab The problem occurs explicitly inside of the Following code does not work and accidentally fails for no reason - the $stateProvider.state('auth', {
url: '',
abstract: true,
resolve: {
'currentUser': function($auth) {
return $auth.awaitUser();
}
}
}) I replaced now the $stateProvider.state('auth', {
url: '',
abstract: true,
resolve: {
'currentUser': function($q) {
var defer = $q.defer();
Meteor.autorun(c => {
let loggingIn = Meteor.loggingIn();
if (!loggingIn) {
if (Meteor.userId()) {
defer.resolve();
} else {
defer.reject();
}
c.stop();
}
});
return defer.promise;
}
}
}) I suspect the |
I made a very small change inside of var computation = this.autorun(function (computation) { to var computation = Meteor.autorun(function (computation) { And now the resolve handler works as expected. I'm getting the feeling that |
One important thing how to actually trigger this error, because most of the time on page reloads it works: |
@dohomi you mentioned something about subscriptions. We actually had a similar issue which was already fixed, #8. Sadly I can't reproduce this problem so I wish I could help you but I can't, I used |
Maybe there is some sort of a synchronous error thrown in the resolve handler and angular silently ignores it. |
I opened this issue where I had to switch back to |
Is there anything against changing |
@dohomi @mxab I'm having troubles reproducing the issue. If we can may a call or something it would be much easier and we can go through it together. Feel free to contact me on the email address presented in my Github account and I would be more than happy to listen and try to help you :-) edit: |
Sounds good, we are currently trying to isolate the issue without luck, I want to make some more tests. I first got the feeling that the defer.resolve(user) somehow does not trigger the then but currently it looks more like that the autorun is not that reactive on the logginIn() call as it should. |
Hi @DAB0mB I did some more debugging. I still don't know why this is only happening in our project but what I found out that something stops the This is my own implementation in my ui-router resolve that I think does pretty much the same thing as the
Everytime I reload the page the
As the autorun is stopped the deferred is never resolve nor rejected, which seems to be our issue. If I surround my whole implementation with another
|
Just some more notes on the issue, it seems that during the setup of the autorun there is an active computation
which then leads the accounts package when it does the |
It maybe related to the same issue that is happening here |
@mxab I'm not sure which package is causing this problem, but look at the test scenario I wrote: it('should keep waiting for user once an outer computation has stopped', function(done) {
login();
function login() {
Accounts.login('tempUser').onStart(function() {
awaitUser();
}).onEnd(function() {
scope.$$afterFlush('$$throttledDigest');
})
}
function awaitUser() {
var c = Tracker.autorun(function(c) {
Tracker.onInvalidate(function() {
c.stop();
});
scope.$awaitUser().then(done);
});
c.invalidate();
}
}); It seems like this is the case, am I right? So it means it's not an issue related only to I hope I understood you correctly, and if so I will solve it by making this test pass and then you can test your app with my fix to see if it really works. |
Hi @DAB0mB const deferred = this.$q.defer();
setTimeout(()=> {
this.$auth.awaitUser().then(deferred.resolve,deferred.reject);
});
return deferred.promise; This works now as expected and the promise resolves correctly and the |
@DAB0mB not sure I fully understand what you test does So the problem as far as I see it is that the $auth.awaitUser is called but there is an active computation and the loggingIn autorun is treated as a nested autorun and is therefore stopped
points to a function in the rootScope service, but not sure if this is really the issue |
… computation has been stopped
@DAB0mB ok will do, which commit/branch should i use for the angular-meteor package? |
ok tested it with
Unfortunately it sill hangs, i put some log outputs in the package to the auths,
During my resolve call in the ui router there seems to be an active computation |
@mxab OK they don't seem like the correct branches, try it with https://github.com/DAB0mB/angular-meteor-auth/tree/fix/%2322 and https://github.com/DAB0mB/angular-meteor/tree/feat/auto-promise. In my new implementation I wrapped it with settimeout() as @dohomi suggested, so it should work. Sorry for the late response. |
Tried this one as well, no difference, I looked a bit more at my stacktrace. The active computation comes from another awaitUser that is happening in a angular |
I just noticed that this problem is not only affecting the awaitUser. We experiencing several
|
Hi everyone, what is the status of this bug? I belive i have the same problem but as i see fix is waiting for some time now? |
@otporsad it is kind of good to hear that someone else has this issue as well. I found out that this issue is actually not only affecting the auth package but more or less all initial subscriptions as well (randomly). One thing how I finally mitigated this problem is to remove all direct calls for Could you check if this might help in your case as well? |
My problem is with resolve in router. Now the app hangs while loading that route. If i comment out return $auth.awaitUser(); route loads as expected. I have also one more resolve item that calls a service that has tracker autorun and it hangs to. I dont know if that is related. If i put $auth.awaitUser in $timeout like this:
but still problem is not solved. I have been keeping an eye on this issue for days hoping someone smarter will figure something out but no luck :( But worst thing is that sometimes it reloads and everything works as expected. In my experience this happends when browser window is open and not touched. Then following a file edit meteor reloads the page and route sometimes works as expected, but mostly not. If there is anything i can help to test or solve this please let me know. |
Could you check the stacktrace in the resolve call to see if and which computation may already be running?
Also do you use the |
Sorry for formatting, i dont use those packages. Trace: but dont understand much... $stateProvider.state.resolve.currentUser @ status.routes.js:15 |
Ok unfortunately there is nothing I could spot directly, but it looks like there is already await computation running.
Just to be sure, that is really not resolving, could you extend the resolve:
The problem should be there if you don't see the `WAS COMPUTATION ACTIVE?`` And one more thing could you show how you start the app ( |
I start my app with: I do not see |
can you show me what is at |
angular-meteor-auth.js:90
angular-meteor.js:1756
|
Good morning all, joining the group with the exact same issue. (Tracker.active) which make the computation seen as nested and then failing lamentably. I am not using meteor-auth, but a quite similar implementation than @mxab I am going to investiguate more to find out the root cause of this ... |
@anymos You can try to check if it works for you if you start angular after the initial flush
|
@mxab, that s interesting, I was thinking that using an afterFluch as you was suggesting to startAngular would have worked. I still have the tracekrActive even so I will continue to try to find out, it must be somewhere in the code ;-) |
ok, this was just an @otporsad I discussed, for me it kind of works to make sure that any potential autorun inside a angular run is scheduled after a $timeout |
I agree that there something linked to the $timeout, this is actaully waht I use at the moment to overcome the issue. But I am not really sure what is the root cause, I have another application that is really similar to the one I have trouble with. I am still investigating comparing the code line by line to try to find out the root cause of it. it s a matter or time, but I will find it |
ok progressing it s coming, in my case from a node_modules. Trying to find out which one now |
I found the offensive package: I have changed : "angular-ui-router": "^0.3.1", to "angular-ui-router": "^0.2.18" and the problem disappear. Absolutely no idea why it is like that. but ti solved it. such a pain to nail it down. I believe the next step would to find out what is the difference between those version to get the root cause of the problem @mxab, could you kindly check on your side if you have the same version and if it s solving the issue ? |
0.3.1, I can try to check if it works, but as far as I remember the issue was quite random, and I need to revert all the runs |
"angular-ui-router": "^0.3.0" is having the same problem |
for me its a 100% coming up at each time, it s why I am taking the time to find out where it s coming from, as from what I read a lot of time it s random and thus impossible to find out |
unfortunately not that much time left to investigate until the end to find out the real root cause. I fail to understand why and how router ui can have a side effect on the meteor computation |
Hi,
we experience some resolving/rejecting issue in our application. we call requireUser but the then handlers are never called.
I started todo some logging in the metoer-angular-auth but it looks ok
it autoruns, finds a valid user, enqueues the deferred.resolve int the $$afterFlush, the Tracker.afterFlush gets also called, but then it disappears.
any ideas what the problem might be?
The text was updated successfully, but these errors were encountered: