Realm-java: [Fatal Exception: io.realm.exceptions.RealmError: Unrecoverable error. write(): failed: No space left]

Created on 28 Dec 2017  路  7Comments  路  Source: realm/realm-java

Realm version Android: 4.1.0 with "io.realm:realm-gradle-plugin:4.1.0"

Stacktrace crash:

Fatal Exception: io.realm.exceptions.RealmError: Unrecoverable error. write(): failed: No space left on device in /home/cc/repo/realm/release/realm/realm-library/src/main/cpp/io_realm_internal_SharedRealm.cpp line 101
       at io.realm.internal.SharedRealm.nativeGetSharedRealm(SourceFile)
       at io.realm.internal.SharedRealm.(SourceFile)
       at io.realm.internal.SharedRealm.getInstance(SourceFile:241)
       at io.realm.internal.SharedRealm.getInstance(SourceFile:231)
       at io.realm.RealmCache.doCreateRealmOrGetFromCache(SourceFile:319)
       at io.realm.RealmCache.createRealmOrGetFromCache(SourceFile:282)
       at io.realm.Realm.getInstance(SourceFile:352)
       at it.ideasolutions.tdownloader.browser.BrowserRepository.addHistoryEntryAsynk(SourceFile:38)
       at it.ideasolutions.tdownloader.browser.BrowserViewController.onUpdateHistory(SourceFile:1336)
       at it.ideasolutions.browser.BrowserController$3.onTabReceivedTitle(SourceFile:449)
       at it.ideasolutions.browser.Tab$1.onReceivedTitle(SourceFile:183)
       at com.android.webview.chromium.WebViewContentsClientAdapter.onReceivedTitle(WebViewContentsClientAdapter.java:657)
       at org.chromium.android_webview.AwContentsClientCallbackHelper$MyHandler.handleMessage(AwContentsClientCallbackHelper.java:206)

Method that raises the crash:

public void addHistoryEntryAsynk(final HistoryEntry entry, final StorageManagerAddHistoryListener listener) {
        try {
            Realm realm = Realm.getInstance(TDownloadedApplication.getInstance().getUpdatedConfigRealmArchive());
            realm.executeTransactionAsync(new Realm.Transaction() {
                @Override
                public void execute(Realm bgRealm) {
                    HistoryEntry entryLoaded = bgRealm.where(HistoryEntry.class).equalTo("idUrlData", entry.getIdUrlData()).findFirst();
                    if (entryLoaded != null) {
                        entryLoaded.setLastvisitedTimeStamp(entry.getLastvisitedTimeStamp());
                        entryLoaded.setLastVisitedDate(entry.getLastVisitedDate());
                        entryLoaded.setTitle(entry.getTitle());
                        bgRealm.copyToRealmOrUpdate(entryLoaded);
                    } else
                        bgRealm.copyToRealmOrUpdate(entry);
                }
            }, () -> listener.onHistoryEntryAddedSuccess(), error -> listener.onHistoryEntryAddedError());
        } catch (Exception ex) {
            listener.onHistoryEntryAddedError();
        }
    }`

Method that gives the RealmConfiguration in Application class:

`public RealmConfiguration getUpdatedConfigRealmArchive() throws IllegalStateException {
        synchronized (lockConfigurationRealm) {
            int permission = ActivityCompat.checkSelfPermission(this, android.Manifest.permission.WRITE_EXTERNAL_STORAGE);
            if (permission != PackageManager.PERMISSION_GRANTED) {
                throw new IllegalStateException("db not ready for permissions");
            }
            if (configurationRealmArchive == null) {
                File directory = new File(Environment.getExternalStorageDirectory(), ConstantsApp.ROOT_DIRECTORY_FOLDER);
                File realmDBFolder = new File(directory, ConstantsApp.REALM_ARCHIVE_DIRECTORY_FOLDER);
                configurationRealmArchive = new RealmConfiguration.Builder().directory(realmDBFolder).name(ConstantsApp.REALM_ARCHIVE_NAME).schemaVersion(ConstantsApp.REALM_SCHEMA_VERSION).build();
                try {
                    Realm.migrateRealm(configurationRealmArchive, new MigrationRealm());
                } catch (Exception ex) {
                    //ignore error
                    ex.printStackTrace();
                }
                Realm.setDefaultConfiguration(configurationRealmArchive);
                return configurationRealmArchive;
            } else
                return configurationRealmArchive;
        }
    }

On 7.1k users in my beta application i have 69 crash on different android os versions.

Is it a bug in my code? Can i prevent this crash?

T-Help

Most helpful comment

Today , I catch this exception from our crash reprot service . I don't know whether be resolved by ACID properties .
we use gradle:plugin:5.7.0

this exception happend in androidsystem 6.0 .

Non-fatal Exception: io.realm.exceptions.RealmError: Unrecoverable error. write() failed: No space left on device in /Users/cm/Realm/realm-java/realm/realm-library/src/main/cpp/io_realm_internal_OsSharedRealm.cpp line 144
at io.realm.internal.OsSharedRealm.nativeCommitTransaction(OsSharedRealm.java)
at io.realm.internal.OsSharedRealm.commitTransaction(OsSharedRealm.java:273)
at io.realm.BaseRealm.commitTransaction(BaseRealm.java:414)
at io.realm.Realm.commitTransaction(Realm.java:143)
at io.realm.Realm$1.run(Realm.java:1545)
at io.realm.internal.async.BgPriorityRunnable.run(BgPriorityRunnable.java:34)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:423)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
at java.lang.Thread.run(Thread.java:818)

All 7 comments

If your users are running out of space for other reasons, there isn't much you can do about it. But try reading: https://realm.io/docs/java/latest/#faq-large-realm-file-size

I can't prevent (catch) this issue and show at the user that there's no space left? I want avoid the crash , but even try to catch , the app crashes due to the native crash in realm.

Is it not possible catch this type of error before a realm operation is made? Any check?

As you can see, it'd be catch(RealmError realmError) and check for the message contains no space.

You do close Realm instances on background threads, right?

Yes i do, in every background thread. I think that is not a bug in my code (not close realm in background) because the app is used a lot from the users with many sessions and the crash rate is low. But it's first crash in fabric.

Is it correct for you to catch this type error with catch(Realm error) ? I red that is not good to catch this type of error , may corrupt the realm. But if is no space left is a good choice?

Since Realm has ACID properties, it should be safe against running out of disk space, but no more writes are possible. So catching and closing everything as soon as possible is an option.

I assume that answers your question. If not, feel free to reopen.

Today , I catch this exception from our crash reprot service . I don't know whether be resolved by ACID properties .
we use gradle:plugin:5.7.0

this exception happend in androidsystem 6.0 .

Non-fatal Exception: io.realm.exceptions.RealmError: Unrecoverable error. write() failed: No space left on device in /Users/cm/Realm/realm-java/realm/realm-library/src/main/cpp/io_realm_internal_OsSharedRealm.cpp line 144
at io.realm.internal.OsSharedRealm.nativeCommitTransaction(OsSharedRealm.java)
at io.realm.internal.OsSharedRealm.commitTransaction(OsSharedRealm.java:273)
at io.realm.BaseRealm.commitTransaction(BaseRealm.java:414)
at io.realm.Realm.commitTransaction(Realm.java:143)
at io.realm.Realm$1.run(Realm.java:1545)
at io.realm.internal.async.BgPriorityRunnable.run(BgPriorityRunnable.java:34)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:423)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
at java.lang.Thread.run(Thread.java:818)

} catch (Throwable e) {
Log.d("Unread Message ", e.toString());
}

I solved by using Throwable

Was this page helpful?
0 / 5 - 0 ratings

Related issues

mithrann picture mithrann  路  3Comments

cmelchior picture cmelchior  路  3Comments

AAChartModel picture AAChartModel  路  3Comments

bryanspano picture bryanspano  路  3Comments

AlbertVilaCalvo picture AlbertVilaCalvo  路  3Comments