dfinity / vscode-motoko

Motoko language support for VS Code.
Apache License 2.0
42 stars 16 forks source link

Language server not working/Heap out of memory #278

Closed Gekctek closed 6 months ago

Gekctek commented 6 months ago

I am trying to diagnose why my vscode motoko extension has just stopped putting anything like errors/warnings in vscode anymore

I have tried

Upon looking I find this error in my output, no matter the cases listed above

Loading packages for directory: /home/gekctek/git/daoball
Running `mops sources` in directory: /home/gekctek/git/daoball
Received: ["--package","base",".mops/base@0.11.0/src","--package","itertools",".mops/itertools@0.2.1/src","--package","datetime",".mops/_github/datetime#28e765bf5bb6b9d75a9416713ab863bea0d4a61f/src","--package","ic",".mops/ic@1.0.1/src","--package","test",".mops/test@1.2.0/src","--package","xtended-text",".mops/xtended-text@0.2.5/src","--package","xtended-numbers",".mops/xtended-numbers@0.2.1/src","--package","icrc3-mo",".mops/icrc3-mo@0.2.3/src","--package","stable-write-only",".mops/_github/stable-write-only#v0.1.0@02e9aac74bdbed86b52ebed985d82b6ef66a76d8/src","--package","map9",".mops/_github/map9#v9.0.1@10b68f6ea8df5e72dfa4c07a50c8bb60a916c233/src","--package","vector",".mops/vector@0.2.0/src","--package","sha2",".mops/sha2@0.0.4/src","--package","rep-indy-hash",".mops/rep-indy-hash@0.1.1/src","--package","encoding",".mops/_github/encoding#v0.4.1@2711d18727e954b11afc0d37945608512b5fbce2/src","--package","base-0.7.3",".mops/_github/base-0.7.3#aafcdee0c8328087aeed506e64aa2ff4ed329b47/src","--package","array",".mops/_github/array#v0.2.1/src","--package","motoko_numbers",".mops/_github/motoko_numbers#v1.1.0@773953141f976ccdfc2e6a2c451b841a53bb39a0/src","--package","cert",".mops/_github/cert#v0.1.3@c403ffec0a60f658a1009976c785aa567ff0da77/src","--package","sha256",".mops/_github/sha256#9e2468f51ef060ae04fde8d573183191bda30189/src","--package","cbor",".mops/_github/cbor#5adf22b177d187d076b222e94b3fdf071b7c0b65/src","--package","sha224",".mops/_github/sha224#82e0aa1a77a8c0a2f98332b59ffc242d820e62cb/src","--package","icrc7-mo",".mops/icrc7-mo@0.3.1/src","--package","candy_0_3_0",".mops/_github/candy_0_3_0#v0.3.0@907a4e7363aac6c6a4e114ebc73e3d3f21e138af/src","--package","stablebuffer",".mops/_github/stablebuffer#v0.2.0@110660769d11ba93c618dc4712525d20503bdc37/src","--package","stablebuffer_1_3_0",".mops/_github/stablebuffer_1_3_0#v1.3.0@acdde6bb5b939227997cebdbb8919d2e6da8691c/src","--package","encoding_0_4_1",".mops/_github/encoding_0_4_1#v0.4.1@2711d18727e954b11afc0d37945608512b5fbce2/src","--package","icrc30-mo",".mops/icrc30-mo@0.3.1/src","--package","ic-certification",".mops/ic-certification@0.1.3/src","--package","random",".mops/_github/random#0a02c4b819fb29eee9b74ebb2e5fd1ccf351206e/src",""]
Package: base -> /home/gekctek/git/daoball/.mops/base@0.11.0/src (file:///home/gekctek/git/daoball)
Package: itertools -> /home/gekctek/git/daoball/.mops/itertools@0.2.1/src (file:///home/gekctek/git/daoball)
Package: datetime -> /home/gekctek/git/daoball/.mops/_github/datetime#28e765bf5bb6b9d75a9416713ab863bea0d4a61f/src (file:///home/gekctek/git/daoball)
Package: ic -> /home/gekctek/git/daoball/.mops/ic@1.0.1/src (file:///home/gekctek/git/daoball)
Package: test -> /home/gekctek/git/daoball/.mops/test@1.2.0/src (file:///home/gekctek/git/daoball)
Package: xtended-text -> /home/gekctek/git/daoball/.mops/xtended-text@0.2.5/src (file:///home/gekctek/git/daoball)
Package: xtended-numbers -> /home/gekctek/git/daoball/.mops/xtended-numbers@0.2.1/src (file:///home/gekctek/git/daoball)
Package: icrc3-mo -> /home/gekctek/git/daoball/.mops/icrc3-mo@0.2.3/src (file:///home/gekctek/git/daoball)
Package: stable-write-only -> /home/gekctek/git/daoball/.mops/_github/stable-write-only#v0.1.0@02e9aac74bdbed86b52ebed985d82b6ef66a76d8/src (file:///home/gekctek/git/daoball)
Package: map9 -> /home/gekctek/git/daoball/.mops/_github/map9#v9.0.1@10b68f6ea8df5e72dfa4c07a50c8bb60a916c233/src (file:///home/gekctek/git/daoball)
Package: vector -> /home/gekctek/git/daoball/.mops/vector@0.2.0/src (file:///home/gekctek/git/daoball)
Package: sha2 -> /home/gekctek/git/daoball/.mops/sha2@0.0.4/src (file:///home/gekctek/git/daoball)
Package: rep-indy-hash -> /home/gekctek/git/daoball/.mops/rep-indy-hash@0.1.1/src (file:///home/gekctek/git/daoball)
Package: encoding -> /home/gekctek/git/daoball/.mops/_github/encoding#v0.4.1@2711d18727e954b11afc0d37945608512b5fbce2/src (file:///home/gekctek/git/daoball)
Package: base-0.7.3 -> /home/gekctek/git/daoball/.mops/_github/base-0.7.3#aafcdee0c8328087aeed506e64aa2ff4ed329b47/src (file:///home/gekctek/git/daoball)
Package: array -> /home/gekctek/git/daoball/.mops/_github/array#v0.2.1/src (file:///home/gekctek/git/daoball)
Package: motoko_numbers -> /home/gekctek/git/daoball/.mops/_github/motoko_numbers#v1.1.0@773953141f976ccdfc2e6a2c451b841a53bb39a0/src (file:///home/gekctek/git/daoball)
Package: cert -> /home/gekctek/git/daoball/.mops/_github/cert#v0.1.3@c403ffec0a60f658a1009976c785aa567ff0da77/src (file:///home/gekctek/git/daoball)
Package: sha256 -> /home/gekctek/git/daoball/.mops/_github/sha256#9e2468f51ef060ae04fde8d573183191bda30189/src (file:///home/gekctek/git/daoball)
Package: cbor -> /home/gekctek/git/daoball/.mops/_github/cbor#5adf22b177d187d076b222e94b3fdf071b7c0b65/src (file:///home/gekctek/git/daoball)
Package: sha224 -> /home/gekctek/git/daoball/.mops/_github/sha224#82e0aa1a77a8c0a2f98332b59ffc242d820e62cb/src (file:///home/gekctek/git/daoball)
Package: icrc7-mo -> /home/gekctek/git/daoball/.mops/icrc7-mo@0.3.1/src (file:///home/gekctek/git/daoball)
Package: candy_0_3_0 -> /home/gekctek/git/daoball/.mops/_github/candy_0_3_0#v0.3.0@907a4e7363aac6c6a4e114ebc73e3d3f21e138af/src (file:///home/gekctek/git/daoball)
Package: stablebuffer -> /home/gekctek/git/daoball/.mops/_github/stablebuffer#v0.2.0@110660769d11ba93c618dc4712525d20503bdc37/src (file:///home/gekctek/git/daoball)
Package: stablebuffer_1_3_0 -> /home/gekctek/git/daoball/.mops/_github/stablebuffer_1_3_0#v1.3.0@acdde6bb5b939227997cebdbb8919d2e6da8691c/src (file:///home/gekctek/git/daoball)
Package: encoding_0_4_1 -> /home/gekctek/git/daoball/.mops/_github/encoding_0_4_1#v0.4.1@2711d18727e954b11afc0d37945608512b5fbce2/src (file:///home/gekctek/git/daoball)
Package: icrc30-mo -> /home/gekctek/git/daoball/.mops/icrc30-mo@0.3.1/src (file:///home/gekctek/git/daoball)
Package: ic-certification -> /home/gekctek/git/daoball/.mops/ic-certification@0.1.3/src (file:///home/gekctek/git/daoball)
Package: random -> /home/gekctek/git/daoball/.mops/_github/random#0a02c4b819fb29eee9b74ebb2e5fd1ccf351206e/src (file:///home/gekctek/git/daoball)

<--- Last few GCs --->

[13240:0x611fef0]   102007 ms: Scavenge 4041.0 (4136.6) -> 4038.6 (4137.4) MB, 7.0 / 0.0 ms  (average mu = 0.786, current mu = 0.655) allocation failure; 
[13240:0x611fef0]   102016 ms: Scavenge 4042.1 (4137.4) -> 4039.6 (4138.4) MB, 7.4 / 0.0 ms  (average mu = 0.786, current mu = 0.655) allocation failure; 
[13240:0x611fef0]   103174 ms: Scavenge 4043.2 (4138.4) -> 4040.7 (4146.4) MB, 1155.7 / 0.0 ms  (average mu = 0.786, current mu = 0.655) allocation failure; 

<--- JS stacktrace --->

FATAL ERROR: Reached heap limit Allocation failed - JavaScript heap out of memory
 1: 0xb881c0 node::Abort() [/home/gekctek/.vscode-server/bin/863d2581ecda6849923a2118d93a088b0745d9d6/node]
 2: 0xa92a26  [/home/gekctek/.vscode-server/bin/863d2581ecda6849923a2118d93a088b0745d9d6/node]
 3: 0xd73d50 v8::Utils::ReportOOMFailure(v8::internal::Isolate*, char const*, bool) [/home/gekctek/.vscode-server/bin/863d2581ecda6849923a2118d93a088b0745d9d6/node]
 4: 0xd740f7 v8::internal::V8::FatalProcessOutOfMemory(v8::internal::Isolate*, char const*, bool) [/home/gekctek/.vscode-server/bin/863d2581ecda6849923a2118d93a088b0745d9d6/node]
 5: 0xf51a95  [/home/gekctek/.vscode-server/bin/863d2581ecda6849923a2118d93a088b0745d9d6/node]
 6: 0xf63f0d v8::internal::Heap::CollectGarbage(v8::internal::AllocationSpace, v8::internal::GarbageCollectionReason, v8::GCCallbackFlags) [/home/gekctek/.vscode-server/bin/863d2581ecda6849923a2118d93a088b0745d9d6/node]
 7: 0xf3e65e v8::internal::HeapAllocator::AllocateRawWithLightRetrySlowPath(int, v8::internal::AllocationType, v8::internal::AllocationOrigin, v8::internal::AllocationAlignment) [/home/gekctek/.vscode-server/bin/863d2581ecda6849923a2118d93a088b0745d9d6/node]
 8: 0xf3fa17 v8::internal::HeapAllocator::AllocateRawWithRetryOrFailSlowPath(int, v8::internal::AllocationType, v8::internal::AllocationOrigin, v8::internal::AllocationAlignment) [/home/gekctek/.vscode-server/bin/863d2581ecda6849923a2118d93a088b0745d9d6/node]
 9: 0xf20e7a v8::internal::Factory::NewFillerObject(int, v8::internal::AllocationAlignment, v8::internal::AllocationType, v8::internal::AllocationOrigin) [/home/gekctek/.vscode-server/bin/863d2581ecda6849923a2118d93a088b0745d9d6/node]
10: 0x12e84bf v8::internal::Runtime_AllocateInYoungGeneration(int, unsigned long*, v8::internal::Isolate*) [/home/gekctek/.vscode-server/bin/863d2581ecda6849923a2118d93a088b0745d9d6/node]
11: 0x1724e39  [/home/gekctek/.vscode-server/bin/863d2581ecda6849923a2118d93a088b0745d9d6/node]
[Info  - 12:11:08 PM] Connection to server got closed. Server will restart.
Loading packages for directory: /home/gekctek/git/daoball

Any help in diagnosing the issue would be appreciated, its slowing down my development to use

My project https://github.com/edjCase/daoball/ main branch

rvanasa commented 6 months ago

Thanks for the repro link. Everything seems to work on my end, so this might be specific to your system. I'll see if there's any way to reduce the peak memory usage in case that's the root of the issue.

Does this still happen with previous versions of the Motoko extension?

Gekctek commented 6 months ago

Thanks for the repro link. Everything seems to work on my end, so this might be specific to your system. I'll see if there's any way to reduce the peak memory usage in case that's the root of the issue.

Does this still happen with previous versions of the Motoko extension?

Yes, it cuts out once in a while historically, but I have always just restarted VSCode and that can help

This time, it just seems stuck broken. Im fairly confident that i didnt update vscode extension or dfx, so its probably just something weird on my computer. Ill try another

Any tips for diagnosing where the issue could be? Is it the out of memory or is that something else, i never looked to see if it was a problem before

Gekctek commented 6 months ago

@rvanasa I ran it on my laptop, same repo and i get the same thing with the out of memory and no showing of errors/warnings in vscode, only see them in the CLI when i do a CLI build

I dont think I mention that I am using WSL2 for both of my computers, windows 11

rvanasa commented 6 months ago

Okay, good to know about WSL. This might just be caused by running out of memory in VS Code. It's possible that other extensions are contributing to the memory usage, although I'll also try to find some optimizations next time I get a chance to work on the Motoko extension again.

It might be worth trying to remove other extensions as another debugging step to narrow down the issue. If it's specifically the Motoko extension, then I'll prioritize looking for a fix in the next few days (currently juggling a lot of work items).

Also, for repro purposes, are you using the latest version of the extension (v0.16.3) on both computers, and the same thing occurs with earlier versions (e.g. v0.16.0)?

Gekctek commented 6 months ago

Some more context

USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
gekctek 2433 177 26.9 15365964 4395324 pts/2 Rl+ 09:57 3:09 /home/gekctek/.vscode-server/bin/863d2581ecda6849923a2118d93a088b0745d9d6/node --stack-size=1361 /home/gekctek/.vscode-server/extensions/dfinity-foundation.vscode-motoko-0.16.3/out/server.js --node-ipc --clientProcessId=19163

It seems specifically that the motoko extension is taking up a good chunk of my memory

Going to test with other versions

I feel like there is something with my code that is triggering a bug?

Gekctek commented 6 months ago

I am testing these out with rebooting my wsl2 instance just to make sure i have a clean slate to test

Changing to different extension versions I know worked like 0.16.0 has the same issue

I switched repositories to https://github.com/edjCase/motoko_random and IT WORKS, in multiple versions including the latest

So it must be a repo specific issue for https://github.com/edjCase/daoball The question is what, im not sure how to diagnose the specific issue.

Ill try reverting commits again until it works

Gekctek commented 6 months ago

Ok, 'solved'

I deleted the .dfx and .mops directories and restarted and it is now fine

I always noticed that there is a delay in the extension highlighting when starting up. So maybe it was just an issue with too many uncleaned mops packages or something?

Is there a lot of analysis going into these?

rvanasa commented 6 months ago

Thanks for the info, and I'm glad that you were able to resolve the issue! I'll see if we there's anything we can do to reduce unnecessary memory usage, especially if this had something to do with type-checking unused Mops packages.

I'll close the issue for now, and we can re-open if you or anyone else runs into this again in the future.

As a side note, I double-checked and the extension shouldn't be running the type checker on any unused Motoko files. However, this very well might be related to a corner case with the virtual file system used by moc.js from js_of_ocaml.