Multiple listeners support
fatih opened this issue · comments
I have multiple listeners (like two listening on port :8080 and 8081 and one listening to https on 443 port). That means I have now three listeners. However the nature of goagain doesn't allow to use it with several listeners. I can split my app that it runs like three binaries but this would be not a good choice.
I've hacked a little on goagain to support for multiple listeners, a sneak code:
for addr, l := range listeners {
a := reflect.ValueOf(l)
v := a.Elem().FieldByName("fd").Elem()
fd := uintptr(v.FieldByName("sysfd").Int())
if err := os.Setenv("GOAGAIN_FD"+addr, fmt.Sprint(fd)); nil != err {
return err
}
if err := os.Setenv("GOAGAIN_NAME"+addr, fmt.Sprintf("tcp:%s->", l.Addr().String())); nil != err {
return err
}
fmt.Println("FD number is", fd)
files[fd] = os.NewFile(fd, string(v.FieldByName("sysfile").String()))
}
However I don't like the way the file descriptors are created. Because I have to create the array earlier to append the FD's to the files
arary, like:
files := make([]*os.File, 30 )
Here, 30 is just an integer that's large enough. I've tried to use append
on files
array. However when I use append it's breaking goagain with this err:
fork/exec ./go/bin/test_goagain: bad file descriptor
It seems it is working quite well. Do you have any plans to support multiple listeners?
I would merge such a pull request but I don't think I'll be adding that functionality all on my own. For my purposes, at least, there is only one net.Listener
in any program that must be restarted without downtime. The rest, if any, are management ports and other non-critical services that can standby for a moment.
👍 on the concept. Is it possible to incorporate outbound connections too, I wonder..
It's possible to inherit and reconstitute all sorts of file descriptors, sure, but maintaining the application state of each of those file descriptors across process restarts is very hairy.
I have a process that listens on port 80 and 443.. I'm using facebookgo's grace reloader, but it doesnt seem to support upstart. Any chance this would ?