Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

cleanup.go 1.0KB

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