joncrlsn / dque

dque is a fast, embedded, durable queue for Go
MIT License
767 stars 46 forks source link

Dequeue is failing while deleting the segment "The process cannot access the file because it is being used by another process" #30

Open ysaik opened 3 years ago

ysaik commented 3 years ago

Hi, I was trying a simple program to enqueue and dequeue 10 elements. with segment size 5 its failing with below error main.go and go.mod files attached PS C:\Sai_laptop_backup\workspace\golang\dque_test> .\main.exe Enqueued SAI100 1 Enqueued SAI101 2 Enqueued SAI102 3 Enqueued SAI103 4 Enqueued SAI104 5 Enqueued SAI105 6 Enqueued SAI106 7 Enqueued SAI107 8 Enqueued SAI108 9 Enqueued SAI109 10 Dequeued: &{SAI100 1} Dequeued: &{SAI101 2} Dequeued: &{SAI102 3} Dequeued: &{SAI103 4} 2021/07/20 11:22:49 Error dequeuing item:error deleting queue segment C:/Sai_laptop_backup/workspace/golang/dque_test/item-queue/0000000000001.dque. Queue is in an inconsistent state: error deleting file: C:/Sai_laptop_backup/workspace/golang/dque_test/item-queue/0000000000001.dque: remove C:/Sai_laptop_backup/workspace/golang/dque_test/item-queue/0000000000001.dque: The process cannot access the file because it is being used by another process.

ysaik commented 3 years ago

dque_test.zip

main.go and go.mod files are attached

It is failing to remove the first segment from the queue

joncrlsn commented 3 years ago

Hi, Thank you for reporting that. I don't have access to a Windows machine. If you figure it out and find a fix, please create a Pull Request. Or at least let me know what the fix is.

malcolm-white-dti commented 1 year ago

This is an inherent bug with Golang, based on how files are created in Windows. There is a long thread on fixing and changing it (and the Linux people seemed to have won). One of the posts in there has a work around for it.

https://github.com/alexbrainman/goissue34681

I've implemented in a fork I am using, but I also had to make changes in the Flock library because it was using the same call/function.