Skip to content
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

Typescript compiler hangs and starts eating memory #7344

Closed
davyvanlaere opened this issue Mar 2, 2016 · 16 comments
Closed

Typescript compiler hangs and starts eating memory #7344

davyvanlaere opened this issue Mar 2, 2016 · 16 comments
Labels
External Relates to another program, environment, or user action which we cannot control.

Comments

@davyvanlaere
Copy link

TypeScript Version:
1.8.0-beta

Code

    return this.http.request(url, request)
        .catch(initialError => {
            if (initialError && initialError.status === 401 && isSecureCall === true) {
                // token might be expired, try to refresh token
                return me.authService.refreshAuthentication().flatMap((authenticationResult:AuthenticationResult) => {
                    if (authenticationResult.IsAuthenticated == true) {
                        // retry with new token
                        me.authService.setAuthorizationHeader(request.headers);
                        return this.http.request(url, request);
                    }
                    return Observable.throw(initialError);
                });
            }
            else {
                return Observable.throw(initialError);
            }
        });

Expected behavior:

This code has compiled and worked before. (this is a snippet from an angular2 application: if an authenticated request fails because the token has expired, the code tries to use a refresh token to get a new token and retry the request).

Actual behavior:

The compiler starts to hang

I have stripped down my project to the bare minimum to illustrate the problem.
To reproduce; clone this repo:

https://github.com/davyvanlaere/TypescriptCompilerIssue

Then run "npm install", followed by "tsc": the compiler will hang, and the process "Evented I/O for V8 Javascript" will start to eat memory (i let it run for a while and killed it at 1.3gb).

It has something to do with the types of the return statements. If you the replace 2nd "return this.http.request(url, request);" line with "return Observable.throw(initialError);", the compiuler will not hang.

@vladima
Copy link
Contributor

vladima commented Mar 2, 2016

what version of node do you use?

@davyvanlaere
Copy link
Author

v0.12.0

@vladima
Copy link
Contributor

vladima commented Mar 2, 2016

can you try to upgrade to node 5 and see if you still see this issue?

@davyvanlaere
Copy link
Author

Just checked with version 4.3.1 (LTS) and 5.7.0 (stable), problem is gone. I apparently had an ancient node version ...

While running tsc, the process still peaks to 800Mb though (seems alot for such a small workload?)

@vladima
Copy link
Contributor

vladima commented Mar 2, 2016

recent version of rxjs have added more complex type definitions so analyzing them takes lots of time\memory - we already have an issue that tracks it.

@davyvanlaere
Copy link
Author

Darn ... the repo builds, but the project it was distilled from still explodes. I'll see if i can isolate the problem again.

@vladima
Copy link
Contributor

vladima commented Mar 2, 2016

Can you share the actual code so we can be sure that root problem is addressed? We can sign an NDA if necessary.

@davyvanlaere
Copy link
Author

NDA is not necessary, but i prefer not to share it publicly.

@vladima
Copy link
Contributor

vladima commented Mar 2, 2016

Can you send it to vladima at microsoft.com?

@davyvanlaere
Copy link
Author

Sent!

@msklvsk
Copy link

msklvsk commented Mar 17, 2016

Same here, importing and using {Observable} from 'rxjs/Observable' hangs compilation of an angular2 app since rxjs 5.0.0-beta.2

@msklvsk
Copy link

msklvsk commented Mar 17, 2016

(present in TS 1.8.9, node 5.9.0)

@vladima
Copy link
Contributor

vladima commented Mar 17, 2016

this is one of a few similar issues that were reported recently (i.e. #7460 and #7344) that originate from the fact that type declarations in rxjs-5.0.0-beta.2 got more complicated and compiler spends lots of time exploring them. This is one of downsides of structural type system - in order to prove that two types are related their whole structure must be examined. We can short-circuit in a few places (#7474) but in general this problem is pretty hard to solve. Luckily it can be addressed on the consumer side - we are following up with RxJS folks to add a fix that should improve the situation (ReactiveX/rxjs#1475)

@mhegazy mhegazy added the External Relates to another program, environment, or user action which we cannot control. label Mar 17, 2016
@msklvsk
Copy link

msklvsk commented Mar 18, 2016

I forgot to mention that the hang happens on watch-triggered recompile. Initial build succeeds though (~2 sec slower than usual but still succeeds). Is it a known issue or should I post new one concerning successful initial but failed incremental?

@vladima
Copy link
Contributor

vladima commented Mar 18, 2016

we've seen the similar issue before due to significant increase of memory during type relation check - it was resolved after I switched to RxJS version that included ReactiveX/rxjs#1475. Given that this PR is already merged in master ( 👏 ) you can try to build RxJS from master and see if it will help in your case. If issue still exist I'd be very curious if I can somehow get your project for repro to make sure that problem is addressed.

@mhegazy
Copy link
Contributor

mhegazy commented Mar 29, 2016

Updating to latest RxJS beta should address the issue. please reopen if the issue persists on newer versions of the framework.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
External Relates to another program, environment, or user action which we cannot control.
Projects
None yet
Development

No branches or pull requests

4 participants