Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem with function Close() #1

Closed
u-veles-a opened this issue Oct 30, 2019 · 1 comment
Closed

Problem with function Close() #1

u-veles-a opened this issue Oct 30, 2019 · 1 comment

Comments

@u-veles-a
Copy link

Hi.
pool.go

func (p *Pool) Acquire(ctx context.Context) (*Resource, error) {
                        ...

                        **p.allResources** = append(p.allResources, res)
			**p.destructWG.Add(1)**
			p.cond.L.Unlock()
			value, err := p.constructResourceValue(ctx)
			p.cond.L.Lock()
			if err != nil {
				p.allResources = removeResource(p.allResources, res)
				**p.destructWG.Done()**
                        ...
}

func (p *Pool) Close() {
    ...
    for _, res := range **p.idleResources** {
		p.allResources = removeResource(p.allResources, res)
		go p.destructResourceValue(res.value)
   }
  // Different WaitGroup counter
    ...
    **p.destructWG.Wait()**
    // process freezes because
    //  len(p.idleResources) != len(p.allResources)
}

The easiest way to solve:

func (p *Pool) Close() {
    for _, res := range **p.idleResources** {
		p.allResources = removeResource(p.allResources, res)
		go p.destructResourceValue(res.value)
   }
   for _, res := range p.allResources {
		p.allResources = removeResource(p.allResources, res)
		p.destructWG.Done()
    }

...
}

@jackc
Copy link
Owner

jackc commented Jan 26, 2020

Sorry, I don't understand what you mean. Do you have an example that demonstrates this issue?

@jackc jackc closed this as not planned Won't fix, can't repro, duplicate, stale Nov 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants