Skip to content
This repository has been archived by the owner on Mar 5, 2024. It is now read-only.

Commit

Permalink
Fix bug in cleanup code
Browse files Browse the repository at this point in the history
Defer semantics are hard.
I missed that when you call `s.indexReference.Replace(nil).Close()`, the
`Close()` is deferred, but not the `Replace()`.
This resulted in immediately nilling the index upon starting up the http
server, which causes the server to panic.
  • Loading branch information
praboud-stripe committed Apr 13, 2015
1 parent fbd2e28 commit cc1c684
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion sequins.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,9 @@ func (s *sequins) start(address string) error {
// However, this may not be a problem, since you have to shift traffic to
// another instance before shutting down anyway, otherwise you'd have downtime

defer s.indexReference.Replace(nil).Close()
defer func() {
s.indexReference.Replace(nil).Close()
}()

log.Printf("Listening on %s", address)
return http.ListenAndServe(address, s)
Expand Down

0 comments on commit cc1c684

Please sign in to comment.