Giter Site home page Giter Site logo

bug: tests.lib.log: race condition about klb HOT 2 OPEN

katcipis avatar katcipis commented on September 1, 2024
bug: tests.lib.log: race condition

from klb.

Comments (2)

katcipis avatar katcipis commented on September 1, 2024

The problem is here:

	var errs []error
	for {
		// buffered channel avoid goroutine leak
		result := make(chan error, 1)

		go func() {
			l.Printf("retrier: executing work: %s", name)
			result <- work()
		}()

		select {
		case res := <-result:
			{
				if res == nil {
					return nil
				}
				l.Printf("%s: got error: %s", name, res)
				errs = append(errs, res)
			}
		case <-ctx.Done():
			{
				l.Printf("retrier: %s: timeouted, returning all errors", name)
				return append(
					errs,
					errors.New("retrier timeout"),
				)
			}
		}
		// Sometimes we geet an error like: Number of write requests
		// for subscription 'x'
		// exceeded the limit of '1200' for time interval '01:00:00'.
		// Please try again after '5' minutes
		// Before trying again lets backoff a little.
		time.Sleep(backoff)
	}

To prevent Close being called at the same time as a Write I would have to wait all pending work jobs that are running before cancelling the test (and eventually calling tearDown).

The problem is that I do this on purpose exactly to guarantee that if some work goes haywire I guarantee that our teardown function WILL be executed, guaranteeing that resources are ALWAYS cleanedup, even when something locks up forever.

Now I can't think on a better solution then implementing a concurrency safe logger that prevents Write/Read being called concurrently with Close.

There is a discussion about this, and solving this on the os.File don't make sense, but on our particular case it makes sense:

golang/go#10001

from klb.

katcipis avatar katcipis commented on September 1, 2024

After talking with @tiago4orion it seems like a good idea to just leak the fd and not close it at all :-)

from klb.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.