a0x8o / kafka

A high-throughput, distributed, publish-subscribe messaging system
Apache License 2.0
67 stars 171 forks source link

fix: Keep FileOffset opened only the needed time #54

Closed sergio-ropero closed 1 year ago

sergio-ropero commented 1 year ago

In another project we are working on, we have faced an issue when trying to read the file at the same time it's being writen by a heavy process.

This change is already applied in our repository, surpassing errors on corrupted file, but we think this change can be beneficial for other teams or projects.

It's supper simple, just move out from the try-catch block everything that is not related with IO operations (type checks, in memory object loops, ...). That frees the resource and, if it got write before closing, we don't face a java.io.StreamCorruptedException: unexpected EOF in middle of data block exception.

Committer Checklist (excluded from commit message)

sergio-ropero commented 1 year ago

Opened in Apache/Kafka repo: https://github.com/apache/kafka/pull/13464