vrecan/death

Panic occurs if io.Closer is an unhashable type.

lcaballero opened this issue · 1 comments

This explains what is allowed as a key in a map.

The language spec defines this precisely, but in short, comparable types are boolean, numeric, string, pointer, channel, and interface types, and structs or arrays that contain only those types.

Below is a test for the issue I'm describing:

type Unhashable map[string]interface{}
func (u Unhashable) Close() error {
    return nil
}

Convey("Validate death happens cleanly", t, func() {
    u := make(Unhashable)
    death := NewDeath(syscall.SIGTERM)
    syscall.Kill(os.Getpid(), syscall.SIGTERM)
    death.WaitForDeath(u)
})

At the moment death will panic because Unhashable is, well, unhashable, but also an io.Closer. See my suggested solution #17

In summary, it just uses the index of the io.Closer from the internal list of closers. My changes save that index in the closer{} to properly remove from the tracking map.

#17 fixes this