Steps to reproduce:
This is expected since the files are being uploaded to the same location. At the same time, each document with an attachment just contains a reference to the location of the file.
However, I think it's a good idea that each document should have its own folder.
Ideally if a same name exists, the system should create a new name for the file. e.g. file-1.pdf
@djpalshikar If file hash is different then the system creates two different records. As per me, if file hash is same then no need to keep separate versions.

@saurabh6790 this is expected behaviour. But it is not what is happening. The system is replacing the files even they have different content.
@saurabh6790 I think I now see why this is happening. Strangely in case of some files the, I have found empty ContentHash, after upload.

Seems an issue! Will check this.
We are facing the same issue.
We should atleast raise and exception when content hash is empty or file size is 0 and abort the file upload. @shridarpatil can you please send a patch for this.
We have been able to pin this down to socket io, this issue happens when files are uploaded through socket io, if socket io fails and falls back to http POST hashes and file sizes are always recorded, and this issue never happens.
If we stop socket IO service, this issue doesn't occur.
@realvinay I am working on this will send a PR.
Most helpful comment
Ideally if a same name exists, the system should create a new name for the file. e.g. file-1.pdf