Coder Social home page Coder Social logo

facebookarchive / httpdown Goto Github PK

View Code? Open in Web Editor NEW
285.0 17.0 37.0 17 KB

Package httpdown provides http.ConnState enabled graceful termination of http.Server.

Home Page: https://godoc.org/github.com/facebookgo/httpdown

License: MIT License

Go 100.00%

httpdown's Introduction

httpdown Build Status

Documentation: https://godoc.org/github.com/facebookgo/httpdown

Package httpdown provides a library that makes it easy to build a HTTP server that can be shutdown gracefully (that is, without dropping any connections).

If you want graceful restart and not just graceful shutdown, look at the grace package which uses this package underneath but also provides graceful restart.

Usage

Demo HTTP Server with graceful termination: https://github.com/facebookgo/httpdown/blob/master/httpdown_example/main.go

  1. Install the demo application

     go get github.com/facebookgo/httpdown/httpdown_example
    
  2. Start it in the first terminal

     httpdown_example
    

    This will output something like:

     2014/11/18 21:57:50 serving on http://127.0.0.1:8080/ with pid 17
    
  3. In a second terminal start a slow HTTP request

     curl 'http://localhost:8080/?duration=20s'
    
  4. In a third terminal trigger a graceful shutdown (using the pid from your output):

     kill -TERM 17
    

This will demonstrate that the slow request was served before the server was shutdown. You could also have used Ctrl-C instead of kill as the example application triggers graceful shutdown on TERM or INT signals.

httpdown's People

Contributors

daaku avatar fantasist avatar jsha avatar titanous avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

httpdown's Issues

test result in i386 always fail

after compiled with golang 1.8 in i386 setup i got this error:

--- FAIL: TestNewRequestAfterStop (0.01s)
	ensure.go:65: ���������������httpdown_test.go:236: expected error: "(connection refused|connection reset by peer)$" but got a nil error

Access to internal listener variable

When passing a listening address with port 0, a suiting port number is chosen. However, finding out which port was chosen requires access to the listener variable of type net.Listener (?). Private variables makes this to difficult to solve without hacking the library directly.

panic: sync: negative WaitGroup counter

When calling Stop on the httpdown server, i get an panic: sync: negative WaitGroup counter error.

    server := &http.Server{
        Addr:    addr,
        Handler: handlers.CORS()(k.router),
    }

    hd := &httpdown.HTTP{
        StopTimeout: 10 * time.Second,
        KillTimeout: 1 * time.Second,
    }

    if listener, err := net.Listen("tcp", addr); err == nil {
        s := hd.Serve(server, listener)

        // Receive on the shutdown channel will block as
        // nothing is ever sent down it, however once it closes
        // the lock is released and we can tell the server to stop,
        // once stop finishes we can then tell the shutdowner we
        // are done.
        <-k.ShutdownChan()
        s.Stop()
        k.ShutdownComplete()
    }

bug: test TLS always fail in i386 env

test TLS always fail in i386 env using golang 1.8:

seems the httpdown facebook need network connection to work that test?

--- PASS: TestTLS (0.10s)
FAIL
FAIL	github.com/facebookgo/httpdown	0.118s
?   	github.com/facebookgo/httpdown/httpdown_example	[no test files]
dh_auto_test: go test -v -p 10 github.com/facebookgo/httpdown github.com/facebookgo/httpdown/httpdown_example returned exit code 1

Use vendoring for your dependencies

Hi

Since Go 1.6, it is recommended to vendor the dependencies:

https://golang.org/doc/go1.6#go_command

Could you do this in this project? I.e. vendor facebookgo/clock and facebookgo/stats (I recommend git submodules, it works great in my projects).

This way, the exact version of the dependencies is fixed, and in my project, I only have to directly depend on httpdown, and not manually transitively vendor all its dependencies.

Thank you.

Create annotated tags for releases

Hi

It would be great if you tagged the current HEAD with v1.0.0, and in the future, occasionally bump the version and make new tags with new releases. I suggest using the semver.org versioning scheme, where you have major.minor.patch, and you bump the major for incompatible changes and the minor for compatible changes to the API.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.