Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple listeners support #12

Open
fatih opened this issue Jun 18, 2013 · 4 comments
Open

Multiple listeners support #12

fatih opened this issue Jun 18, 2013 · 4 comments

Comments

@fatih
Copy link

fatih commented Jun 18, 2013

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?

@rcrowley
Copy link
Owner

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.

@pwaller
Copy link

pwaller commented Dec 10, 2013

👍 on the concept. Is it possible to incorporate outbound connections too, I wonder..

@rcrowley
Copy link
Owner

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.

@abourget
Copy link

abourget commented May 4, 2015

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 ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants