Closed mgurevin closed 4 years ago
In what program did you observe this problem, btw? Was it nsqd or something else?
I'm using this package in my program to have disk backed channels.
I think the depth method would be better if it returns the real value from the metadata file when the queue is closed. Maybe the last value of the depth before the queue closing can also be used.
Yeah ... maybe something like this, in addition to your fix, would be sufficient:
--- a/diskqueue.go
+++ b/diskqueue.go
@@ -138,7 +138,12 @@ func New(name string, dataPath string, maxBytesPerFile int64,
// Depth returns the depth of the queue
func (d *diskQueue) Depth() int64 {
- return <-d.depthChan
+ depth, ok := <-d.depthChan
+ if !ok {
+ // ioLoop exited
+ depth = d.depth
+ }
+ return depth
}
That was my first attempt too. I prefer this if it's also ok for you.
Yeah that seems fine to me. You want to add that bit to this PR?
Looks like a fixup for #11, thanks.