coreos / torus

Torus Distributed Storage
https://coreos.com/blog/torus-distributed-storage-by-coreos.html
Apache License 2.0
1.78k stars 172 forks source link

close() by defer are not called when os.Exit(1) #333

Closed nak3 closed 7 years ago

nak3 commented 8 years ago

os.Exit(1) doesn't return, so defer close() is not called. For example, nbdAction() have them.

Please refer to https://gobyexample.com/exit

amy commented 8 years ago

@nak3 Hello! Wanted to discuss how to handle this to potentially contribute.

func doTheStuff() int {
    defer fmt.Println("!")

    return 3
}

func main() {
    os.Exit(doTheStuff())
}

http://stackoverflow.com/questions/27629380/how-to-exit-a-go-program-honoring-deferred-calls

Is this solution something y'all think is appropriate?

nak3 commented 8 years ago

Sorry, that's not what I expected. I will send the patch later.