Skip to content

Bucket.Take function will cause a lot of locks #2

@hel2o

Description

@hel2o
 func (b *Bucket) Take(n int64) int64 {
	b.lock.Lock()
	defer b.lock.Unlock()

	if n > b.capacity {
		n = b.capacity
	}

	if n > b.avail {
		if n > b.fill() {
			n = b.avail
		}
	}

	b.avail -= n
	return n
}

When the request volume is large and the user suddenly stops the request, it will cause a large number of locks, so that the goroutine does not release, and the memory is not released.

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