Comments (6)
Gotcha. Yeah I was able to reproduce this locally and I will try to figure out the best way to update the signal handlers to prevent this, but yes - as you mentioned - using app.Run
will cause Fx to respond to signals automatically. So if you want to workaround this for now you can either:
- Not manually call shutdown when you receive a signal
- Use
app.Start
and then callapp.Stop
when a signal comes intosigChan
. Using Start/Stop instead of Run in this way will no longer cause Fx to register its own signal handlers as of v1.22.1.
from fx.
Thanks for your quick reply and for the workarounds.
from fx.
Hey @ogaca-dd thanks for the report, let me look into this.
Can I ask what kinds of situations you're experiencing where a shutdown signal and an OS signal are being sent at roughly the same time?
from fx.
@JacobOaks
Thanks for your quick answer.
In the situation described above, I am experiencing a dead lock meaning the application try to stop but freeze forever.
from fx.
Hey @ogaca-dd - I understand. My question is why would an application call shutdowner.Shutdown()
after it gets killed? The example you provide seems pretty contrived so I'm just trying to better understand the real-world impact here.
from fx.
The following code is the simplest code I found to reproduce the issue.
func main() {
fx.New(fx.Invoke(func(shutdowner fx.Shutdowner) {
go func() {
_ = syscall.Kill(syscall.Getpid(), syscall.SIGINT)
_ = shutdowner.Shutdown()
}()
})).Run()
}
Our real code looks like
sigChan := make(chan os.Signal, 1)
signal.Notify(sigChan, syscall.SIGINT, syscall.SIGTERM, syscall.SIGPIPE)
for signo := range sigChan {
switch signo {
case syscall.SIGINT, syscall.SIGTERM:
log.Infof("Received signal %d (%v)", signo, signo)
shutdowner.Shutdown()
return
}
// Some code here
}
}
I know that fx already handles signals and this code should be written differently (This code was not updated during our migration to fx).
Anyway, the code I pointed contains a dead lock which was tricky to find. In our case, this freeze happens randomly:
- The frequency of the issue depends on the OS
- Adding debugging logs decreases significantly the occurence of the issue which make it harder to catch.
I understand it may not be a correct usage of fx but as a user I don't expect to have my application freeze randomly in a such case.
from fx.
Related Issues (20)
- fx.Decorate does not add a missing object to the module HOT 3
- When combining fx.As to annotate return type as interface with optional parameters nil value check is not working as expected HOT 1
- Startup order isn't preserved when using modules HOT 3
- Example test failing in master branch when port 8080 is already in use (89f4a90) HOT 3
- fxevent.Logger: Silence until there's an error
- Slog adapter for fx HOT 4
- Release method HOT 10
- fxtest.Lifecycle: Enforce timeout
- Impossible to inject struct that is part of a group by itself HOT 2
- Support Multiple ParamTags? HOT 1
- signalReceivers should call `Signal.Stop(recv.signals)` when stopped
- Release v1.22.0
- Private supplies HOT 1
- Support multiple ResultTags annotations
- Opt-out of signal handling HOT 12
- Add constructor runtime to fxevent.Run events
- Ability to use fx.As and fx.ResultTags for the same Provider HOT 1
- Decorate does not work if inside fx.Module and Populate is called from outside Module HOT 6
- Quieter fxtest logger
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from fx.