Skip to content
This repository has been archived by the owner on Oct 18, 2024. It is now read-only.

Abnormal IDE state in which files are blank when opened #1551

Closed
gituser1000001 opened this issue Dec 12, 2023 · 6 comments
Closed

Abnormal IDE state in which files are blank when opened #1551

gituser1000001 opened this issue Dec 12, 2023 · 6 comments
Milestone

Comments

@gituser1000001
Copy link

I'm not exactly sure what might cause the IDE to enter this abnormal state. In this state, all files are opened with no content. Every opened file is blank. It really scared me the first time I encountered this, thinking "Oh no, all my work is gone!" :) However, closing down the project and restarting the IDE would reset the abnormal state. The files still have their contents. I'm not sure about unsaved files though.

When closing these blank files, we see this
log message,

IDEEditor                 I   Cannot notify language server. File is null.

This bug is not that rare. Just actively close and open files and it'll happen.

@itsaky
Copy link
Member

itsaky commented Dec 13, 2023

Thanks for the report, I'll look into it.

@Rafael2616
Copy link
Contributor

Rafael2616 commented Dec 16, 2023

I know how this happens. Just open several files, about 15 to 20 and it should happen.

VID-20231216-WA0001.mp4

@itsaky
Copy link
Member

itsaky commented Dec 16, 2023

I know how this happens. Just open several files, about 15 to 20 and it should happen.

Thanks, I was able to reproduce this issue after opening 35 files.

When a file is opened, we make the editor non-editable while the file is being read. Once the contents of the file has been read, we make the editor editable again. In my opinion, opening so many files puts so much load on the CPU that the file read operation is affected.

I'll look into the issue and fix it soon. However, I'm also thinking of imposing a restriction to the number of files that can be opened simultaneously.

@Rafael2616
Copy link
Contributor

Rafael2616 commented Dec 16, 2023

I understood. I remember this started to happen when you did some rework in the editor. after a few commits before you have to stop messing with the IDE

@gituser1000001
Copy link
Author

Are you sure it has something to do with the number of files open?

As a test, I was trying to repeatedy open and close a single file and it happened in less than 2 minutes.

The logs repeatedly showed this

EditorActivity            I   Opening file at index:  0  file:   /storage/emulated/0/AndroidIDEProjects/EmptyProject260Test/app/src/main/java/com/example/emptyproject260test/MainActivity.java 
BootClassProvider         I   Skipping indexing for boot classpath as it is already indexed:  /data/data/com.itsaky.androidide/files/home/android-sdk/platforms/android-33/android.jar 
StopWatch                 D   Indexing 1 bootclasspaths completed in 0ms 
NavDeepLinkBuilder        D   Analyzing:  /storage/emulated/0/AndroidIDEProjects/EmptyProject260Test/app/src/main/java/com/example/emptyproject260test/MainActivity.java 
StopWatch                 D   Parsed treees in 10ms 
StopWatch                 D   Processed trees in 0ms 
StopWatch                 D   Analyzed all trees in 110ms 
NavDeepLinkBuilder        I   Analyze file completed. Found 0 diagnostic items 
EditorActivity            I   Closing file:  /storage/emulated/0/AndroidIDEProjects/EmptyProject260Test/app/src/main/java/com/example/emptyproject260test/MainActivity.java 
StopWatch                 D   Action 'ide.editor.fileTab.close.current' completed in 13ms 
EditorActivity            I   Opening file at index:  0  file:   /storage/emulated/0/AndroidIDEProjects/EmptyProject260Test/app/src/main/java/com/example/emptyproject260test/MainActivity.java 

Nothing unusual right?

@itsaky itsaky added this to the v2.7.0-beta milestone Dec 17, 2023
@itsaky itsaky closed this as completed in cd55f9d Dec 17, 2023
@itsaky
Copy link
Member

itsaky commented Dec 17, 2023

Are you sure it has something to do with the number of files open?

As a test, I was trying to repeatedy open and close a single file and it happened in less than 2 minutes.

I was able to reproduce the issue this way as well.

After a few hours of debugging, I found that the withContext call for reading the file doesn't actually call the method to read the file content. This means that the withContext call blocks the thread and the file reading process is not even started. The reason for this is that when you continuously open and close the files, the file is read using Dispatchers.IO whose thread pool eventually gets exhausted. As a result, further coroutines are not executed.

The issue should have been fixed now. If not, please reopen this bug report.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants