Coder Social home page Coder Social logo

`log.Trigger()` buries panics about go-sdk HOT 2 OPEN

blend avatar blend commented on August 24, 2024
`log.Trigger()` buries panics

from go-sdk.

Comments (2)

dhermes avatar dhermes commented on August 24, 2024

This is where the listener goroutine gets triggered:

go eventListener.Start()

I was hoping the explanation was just that a panic in a goroutine doesn't cause the main goroutine to fail but https://play.golang.org/p/5gkWQhNI-F7 put that hunch to rest.

from go-sdk.

dhermes avatar dhermes commented on August 24, 2024

OK I see the recover():

go-sdk/logger/worker.go

Lines 130 to 135 in 5bb3dbe

defer func() {
if r := recover(); r != nil {
err = ex.New(r)
return
}
}()

and then the place where the recovered panic gets put in an error channel owned by the worker:

go-sdk/logger/worker.go

Lines 121 to 123 in 5bb3dbe

if err = w.Process(e); err != nil && w.Errors != nil {
w.Errors <- err
}


However, when log.Listen() is invoked, it calls NewWorker:

eventListener := NewWorker(listener)

and NewWorker leaves the Worker.Errors channel as nil:

go-sdk/logger/worker.go

Lines 11 to 17 in 5bb3dbe

func NewWorker(listener Listener) *Worker {
return &Worker{
Latch: async.NewLatch(),
Listener: listener,
Work: make(chan EventWithContext, DefaultWorkerQueueDepth),
}
}

so these errors just end up getting swallowed.


This "problem" is not so easy to solve since using a buffered channel, e.g.

	return &Worker{
		Latch:    async.NewLatch(),
		Listener: listener,
		Work:     make(chan EventWithContext, DefaultWorkerQueueDepth),
		Errors:   make(chan error, 100),
	}

would eventually fill up and block the listener fully (until some other code started consuming the Errors channel).

from go-sdk.

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.