Skip to content

[Bug]: A resource failed to call close. #305

@LossyDragon

Description

@LossyDragon

Describe the bug

With android and using StrictMode it looks like we're getting the following warnings which is resulting in some GC locks.

StrictMode policy violation: android.os.strictmode.LeakedClosableViolation: A resource was acquired at attached stack trace but never released. See java.io.Closeable for information on avoiding resource leaks.
	at android.os.StrictMode$AndroidCloseGuardReporter.report(StrictMode.java:1987)
	at dalvik.system.CloseGuard.warnIfOpen(CloseGuard.java:345)
	at java.util.zip.Inflater.finalize(Inflater.java:407)
	at java.lang.Daemons$FinalizerDaemon.doFinalize(Daemons.java:291)
	at java.lang.Daemons$FinalizerDaemon.runInternal(Daemons.java:278)
	at java.lang.Daemons$Daemon.run(Daemons.java:139)
	at java.lang.Thread.run(Thread.java:920)
Caused by: java.lang.Throwable: Explicit termination method 'end' not called
	at dalvik.system.CloseGuard.openWithCallSite(CloseGuard.java:295)
	at dalvik.system.CloseGuard.open(CloseGuard.java:263)
	at java.util.zip.Inflater.<init>(Inflater.java:122)
	at java.util.zip.GZIPInputStream.<init>(GZIPInputStream.java:77)
	at java.util.zip.GZIPInputStream.<init>(GZIPInputStream.java:100)
	at in.dragonbra.javasteam.steam.CMClient.handleMulti(CMClient.java:346)
	at in.dragonbra.javasteam.steam.CMClient.onClientMsgReceived(CMClient.java:245)
	at in.dragonbra.javasteam.steam.steamclient.SteamClient.onClientMsgReceived(SteamClient.kt:207)
	at in.dragonbra.javasteam.steam.CMClient.lambda$new$0$in-dragonbra-javasteam-steam-CMClient(CMClient.java:71)
	at in.dragonbra.javasteam.steam.CMClient$$ExternalSyntheticLambda0.handleEvent(D8$$SyntheticClass:0)
	at in.dragonbra.javasteam.util.event.Event.handleEvent(Event.java:24)
	at in.dragonbra.javasteam.networking.steam3.EnvelopeEncryptedConnection$3.handleEvent(EnvelopeEncryptedConnection.java:62)
	at in.dragonbra.javasteam.networking.steam3.EnvelopeEncryptedConnection$3.handleEvent(EnvelopeEncryptedConnection.java:57)
	at in.dragonbra.javasteam.util.event.Event.handleEvent(Event.java:24)
	at in.dragonbra.javasteam.networking.steam3.Connection.onNetMsgReceived(Connection.java:31)
	at in.dragonbra.javasteam.networking.steam3.TcpConnection$NetLoop.run(TcpConnection.java:245)
	at java.lang.Thread.run(Thread.java:920) 

and

	StrictMode policy violation: android.os.strictmode.LeakedClosableViolation: A resource was acquired at attached stack trace but never released. See java.io.Closeable for information on avoiding resource leaks.
	at android.os.StrictMode$AndroidCloseGuardReporter.report(StrictMode.java:2011)
	at dalvik.system.CloseGuard.warnIfOpen(CloseGuard.java:336)
	at java.io.RandomAccessFile.finalize(RandomAccessFile.java:1256)
	at java.lang.Daemons$FinalizerDaemon.doFinalize(Daemons.java:370)
	at java.lang.Daemons$FinalizerDaemon.processReference(Daemons.java:350)
	at java.lang.Daemons$FinalizerDaemon.runInternal(Daemons.java:322)
	at java.lang.Daemons$Daemon.run(Daemons.java:131)
	at java.lang.Thread.run(Thread.java:1012)
Caused by: java.lang.Throwable: Explicit termination method 'close' not called
	at dalvik.system.CloseGuard.openWithCallSite(CloseGuard.java:288)
	at dalvik.system.CloseGuard.open(CloseGuard.java:257)
	at java.io.RandomAccessFile.<init>(RandomAccessFile.java:310)
	at java.io.RandomAccessFile.<init>(RandomAccessFile.java:237)
	at java.io.RandomAccessFile.<init>(RandomAccessFile.java:154)
	at in.dragonbra.javasteam.steam.contentdownloader.ContentDownloader$downloadSteam3DepotFileChunk$1.invokeSuspend(ContentDownloader.kt:583)
	at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
	at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:100)
	at kotlinx.coroutines.internal.LimitedDispatcher$Worker.run(LimitedDispatcher.kt:113)
	at kotlinx.coroutines.scheduling.TaskImpl.run(Tasks.kt:89)
	at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:586)
	at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:820)
	at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:717)
	at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:704)

The first violation is GZIPInputStream (and ByteArrayOutputStream) not being closed... See #306

The second violation I couldn't come up with a simple fix without having a File Channel exception... This will need to be looked at some more.

To Reproduce

  1. Enable StrictMode
        if (BuildConfig.DEBUG) {
            StrictMode.setVmPolicy(
                VmPolicy.Builder()
                    .detectLeakedClosableObjects()
                    .penaltyLog()
                    .build(),
            )
        }
  1. Use content downloader to download a depot or do something via java steam to use lots of handleMulti in CMClient.
  2. Look at logcat.

Expected behavior

These resources should be closed when finished.

JavaSteam Version

1.6.0-SNAPSHOT

Platform Version

Android

JVM Version

11

Additional Information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions