Skip to content

Corrupted file after write using buffered sink (Kotlin/Native) #1586

@bcmedeiros

Description

@bcmedeiros

I have the following method running on Kotlin/Native linux/amd64:

    fun set(id: String, value: Long) {
        val bookmarkPath = path / id
        FileSystem.SYSTEM.sink(bookmarkPath).use { s ->
            s.buffer().use { b ->
                b.writeUtf8("$value\n")
            }
        }
    }

Even though the content being sent to writeUtf8 is always the output of a Long.toString() followed by a line break, one of the files that is manipulated by this method ended up having its content being 7 zero bytes.

The output of xxd is as below:

[bruno@bruno-desktop ~]$ xxd data/bookmark/bookmark.txt
00000000: 0000 0000 0000 00                        .......

There is also the original file attached in case the output below needs to be verified: bookmark.txt

I think this is some sort of bug in okio for a few reasons:

  1. There is no other method that could have written to this file
  2. value is of type Long, so I can't see how the toString() of a long could have produced 7 zero bytes, nor how could the \n could have been ignored before writeUtf8 is called.
  3. There is always a single copy of the process that could have written to this file, and that's managed by systemd. The file system is a block device, so no network involved.

This process is running for months, file always had a sequence of numerical chars followed by a \n. 2 days ago, though, for some still unknown reason, I found this file with the bogus content above.

Could anyone with good Okio knowledge help me investigate what could be causing that?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions