You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

cleanup.go 1.0 kB

1234567891011121314151617181920212223242526272829303132333435363738
  1. // Copyright 2019 The Gitea Authors. All rights reserved.
  2. // Use of this source code is governed by a MIT-style
  3. // license that can be found in the LICENSE file.
  4. package graceful
  5. import "sync"
  6. var cleanupWaitGroup sync.WaitGroup
  7. func init() {
  8. cleanupWaitGroup = sync.WaitGroup{}
  9. // There are three places that could inherit sockets:
  10. //
  11. // * HTTP or HTTPS main listener
  12. // * HTTP redirection fallback
  13. // * SSH
  14. //
  15. // If you add an additional place you must increment this number
  16. // and add a function to call InformCleanup if it's not going to be used
  17. cleanupWaitGroup.Add(3)
  18. // Wait till we're done getting all of the listeners and then close
  19. // the unused ones
  20. go func() {
  21. cleanupWaitGroup.Wait()
  22. // Ignore the error here there's not much we can do with it
  23. // They're logged in the CloseProvidedListeners function
  24. _ = CloseProvidedListeners()
  25. }()
  26. }
  27. // InformCleanup tells the cleanup wait group that we have either taken a listener
  28. // or will not be taking a listener
  29. func InformCleanup() {
  30. cleanupWaitGroup.Done()
  31. }