Hi !
Featured games (91)
games approved by the League of Dukes
Games in Showcase (800)
Games in Android Showcase (237)
games submitted by our members
Games in WIP (867)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Linux java shutdown io bug  (Read 3423 times)
0 Members and 1 Guest are viewing this topic.
Offline i30817

Junior Devvie

« Posted 2012-07-21 23:49:32 »

I've come to suspect there is some kind of shutdown bug at the interface with the operating system on openjdk and shutdownhooks

To be clear i'm not talking about problems from the jdk (there is a hilarious one where if you try to serialize a File that came from a JFileChooser in a shutdownhook it will throw a exception because JFileChooser 'files' are a fake flyweight object that depends on a shutdown hook of the jdk to not leak memory)

I'm talking about the jvm exiting - naturally, by escaping the main or run of all threads - before the buffers are committed to disk - a outputstream.flush() is NOT the same as a disk sync.

When i tried to get the file descriptor of the corresponding fileoutputstream and force the issue with the sync method during shutdown, sometimes i would get a SyncFailedException.

I only really suspect this because actually getting information after a certain point in the shutdown turns impossible - all 'unflushed' 'unsynced' log files start to go nowhere - found this by repeated experimentation and comparing the point where the log stopped making sense - it just disappeared sometimes late in the shutdown

I suspect the shutdown init.d or upstart or systemd or whatever protocol is turning off the discs before the application shutdown hooks flush the data, therefore missing the final 'sync'.
I also suspect the one sure fire way to prevent this (i already optimized what i have to write to disk by performing amortized writes) is to have a init.d|somethingelse script before umount preventing the normal shutdown sequence from going on if it detects the process still in operation and force a sync in the application at the written files in the shutdownhook.

I'm unhappy with this turn of events and i'd like to rant to whoever designed init.d
And oh, i'd like systemd to do better if it can
Offline sproingie

JGO Kernel

Medals: 202

« Reply #1 - Posted 2012-07-22 01:03:03 »

It sounds to me like some dependencies are screwed up ... nothing should be deactivating the devices until all filesystems on it are unmounted, and those shouldn't unmount until every process is finished.

I don't think SysVInit can even control devices like that, but upstart and systemd can.  What distribution are you using?
Offline i30817

Junior Devvie

« Reply #2 - Posted 2012-07-22 01:17:33 »

Ubuntu whatever the latest.

Here is the 'guilty' code:

    public static void writeObjects(Path objectLocation, Serializable... obj) throws IOException {
        FileOutputStream st = new FileOutputStream(objectLocation.toFile());
        try (ObjectOutputStream s = new ObjectOutputStream(new BufferedOutputStream(st, 20000))) {
            for (Serializable a : obj) {
            int counter = 0;
            while (counter++ < 5) {
                try {
                } catch (SyncFailedException e) {

I added the sync and changed from Files.newOutputStream to fileoutputstream recently, not even sure if it helps (i know syncfailedexception happens sometimes because 'paradoxically' i was able to sometimes write the exception to the log i deleted since, if i tried the sync)

Also the the jvm is not being SIGKILL'ed (or halt'ed) - it's far too little time, i looked at the killing code in the init.d scripts in sendsigs and it has a 10 seconds maximum tolerance by checking for processes every second. Long before that happens the shutdown is progressing and the jvm dies a natural death.

I would expect umounting would flush the goddamned operating system buffers to disk.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline i30817

Junior Devvie

« Reply #3 - Posted 2012-07-22 01:29:18 »

Actually they have a sync just before

I don't know man... this sucks, it's a bug i know it.
edit: the code displayed had a sync BEFORE sending SIGTERM, ie: the signal that starts the shutdownhooks.

umounting is in another place than sendsigs

edit2: actually, cat /etc/init.d/umountfs | grep sync
gives nothing and the actual command seems to be
fstab-decode umount -f -r -d $REG_MTPTS

actually pretty suspicious of the force, but i don't really know anything about umount
Pages: [1]
  ignore  |  Print  

Riven (349 views)
2019-09-04 15:33:17

hadezbladez (5133 views)
2018-11-16 13:46:03

hadezbladez (2015 views)
2018-11-16 13:41:33

hadezbladez (5400 views)
2018-11-16 13:35:35

hadezbladez (1122 views)
2018-11-16 13:32:03

EgonOlsen (4540 views)
2018-06-10 19:43:48

EgonOlsen (5398 views)
2018-06-10 19:43:44

EgonOlsen (3085 views)
2018-06-10 19:43:20

DesertCoockie (3979 views)
2018-05-13 18:23:11

nelsongames (4529 views)
2018-04-24 18:15:36
A NON-ideal modular configuration for Eclipse with JavaFX
by philfrei
2019-12-19 19:35:12

Java Gaming Resources
by philfrei
2019-05-14 16:15:13

Deployment and Packaging
by philfrei
2019-05-08 15:15:36

Deployment and Packaging
by philfrei
2019-05-08 15:13:34

Deployment and Packaging
by philfrei
2019-02-17 20:25:53

Deployment and Packaging
by mudlee
2018-08-22 18:09:50

Java Gaming Resources
by gouessej
2018-08-22 08:19:41

Deployment and Packaging
by gouessej
2018-08-22 08:04:08 is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!