question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

mongodb fails to delete a temporary file

See original GitHub issue

Using maven dependency:

<dependency>
                <groupId>de.flapdoodle.embed</groupId>
                <artifactId>de.flapdoodle.embed.mongo</artifactId>
                <version>1.50.1</version>
                <exclusions>
                    <exclusion>
                        <groupId>org.apache.commons</groupId>
                        <artifactId>commons-lang3</artifactId>
                    </exclusion>
                    <exclusion>
                        <groupId>org.apache.commons</groupId>
                        <artifactId>commons-compress</artifactId>
                    </exclusion>
                </exclusions>
                <scope>test</scope>
            </dependency>

Within Intellij, if I debug a test and shut the test down prematurely (e.g. at a breakpoint) the temporary file that embedded mongo creates does not get deleted (I guess the shutdown hook never runs):

C:\Users\XXX\AppData\Local\Temp\extract-XXX-extractmongod.exe

Additionally, after installing BitDefender, this seems to happen even if I run a whole run without pausing and killing prematurely. I get the message at the end of the test:

[mongod output] 2016-09-16 13:50:24.716  WARN 13120 --- [      Thread-11] d.f.embed.process.io.file.Files          : could not delete C:\Users\XXX\AppData\Local\Temp\extract-XXX-extractmongod.exe. Will try to delete it again when program exits.
2016-09-16 13:50:24.721  WARN 13120 --- [      Thread-19] d.f.embed.process.io.file.Files          : could not delete C:\Users\XXX\AppData\Local\Temp\extract-XXX-extractmongod.exe. Will try to delete it again when program exits.
Exception in thread "Thread-11" java.lang.IllegalStateException: Shutdown in progress
    at java.lang.ApplicationShutdownHooks.add(ApplicationShutdownHooks.java:66)
    at java.lang.Runtime.addShutdownHook(Runtime.java:211)
    at de.flapdoodle.embed.process.io.file.FileCleaner.forceDeleteOnExit(FileCleaner.java:52)
    at de.flapdoodle.embed.process.io.file.Files.forceDelete(Files.java:125)
    at de.flapdoodle.embed.process.extract.ExtractedFileSets.delete(ExtractedFileSets.java:76)
    at de.flapdoodle.embed.process.store.ExtractedArtifactStore.removeFileSet(ExtractedArtifactStore.java:147)
    at de.flapdoodle.embed.process.runtime.Executable.stop(Executable.java:77)
    at de.flapdoodle.embed.process.runtime.Executable$JobKiller.run(Executable.java:90)
    at java.lang.Thread.run(Thread.java:745)

It would be good to have a utility function that I can use to just delete this file at the start of a test.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

5reactions
yogeshlonkarcommented, Nov 23, 2016

Faced same issue, following is a work around that can be used. This should be executed before the start of embedded mongo db

    String tempFile = System.getenv("temp") + File.separator + "extract-" + System.getenv("USERNAME") + "-extractmongod";
    String executable;
    if (System.getenv("OS") != null && System.getenv("OS").contains("Windows")) {
        executable = tempFile + ".exe";
    } else {
        executable = tempFile + ".sh";
    }
    Files.deleteIfExists(new File(executable).toPath());
    Files.deleteIfExists(new File(tempFile + ".pid").toPath());
0reactions
ghostcommented, Oct 9, 2018

It happens when some failure shuts down mongo or tests with mongo prematurely as @manishpatelUK kindly pointed out. Possible solution: delete this file backing up it beforehand. Worked for me.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to delete temporary MapReduce collections in mongoDB
They should be deleted when the connection to the database is closed. See the answers to this question for details and a way...
Read more >
Temporary files not removed when starting up after a clean ...
In SERVER-44391 , we started retaining temporary files in the data directory when starting up after a clean shutdown.
Read more >
Mongod – Failed to unlink socket file /tmp/mongodb-27017
Mongod – Failed to unlink socket file /tmp/mongodb-27017 ... Remove the temporary socket with this command: sudo rm -rf /tmp/mongodb-27017.
Read more >
Can I delete manually data files for entire database in MongoDB
Stopping all mongod and mongos services · Delete all dbPath at PRIMARY hosts · Delete all dbPath at ARBITER hosts · Delete folder...
Read more >
Failed to unlink socket file /tmp/mongodb-27017 - Mkyong.com
To fix it, delete the /tmp/mongodb-27017.sock file manually and start the mongod process. Check the /tmp/mongodb-27017.sock permission again, ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found