Merge pull request #105383 from tkashem/lifecycle-signal
make lifecycle signal thread safe
This commit is contained in:
		@@ -16,6 +16,10 @@ limitations under the License.
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
package server
 | 
					package server
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import (
 | 
				
			||||||
 | 
						"sync"
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/*
 | 
					/*
 | 
				
			||||||
We make an attempt here to identify the events that take place during
 | 
					We make an attempt here to identify the events that take place during
 | 
				
			||||||
lifecycle of the apiserver.
 | 
					lifecycle of the apiserver.
 | 
				
			||||||
@@ -143,22 +147,21 @@ func newLifecycleSignals() lifecycleSignals {
 | 
				
			|||||||
func newNamedChannelWrapper(name string) lifecycleSignal {
 | 
					func newNamedChannelWrapper(name string) lifecycleSignal {
 | 
				
			||||||
	return &namedChannelWrapper{
 | 
						return &namedChannelWrapper{
 | 
				
			||||||
		name: name,
 | 
							name: name,
 | 
				
			||||||
 | 
							once: sync.Once{},
 | 
				
			||||||
		ch:   make(chan struct{}),
 | 
							ch:   make(chan struct{}),
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
type namedChannelWrapper struct {
 | 
					type namedChannelWrapper struct {
 | 
				
			||||||
	name string
 | 
						name string
 | 
				
			||||||
 | 
						once sync.Once
 | 
				
			||||||
	ch   chan struct{}
 | 
						ch   chan struct{}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (e *namedChannelWrapper) Signal() {
 | 
					func (e *namedChannelWrapper) Signal() {
 | 
				
			||||||
	select {
 | 
						e.once.Do(func() {
 | 
				
			||||||
	case <-e.ch:
 | 
					 | 
				
			||||||
		// already closed, don't close again.
 | 
					 | 
				
			||||||
	default:
 | 
					 | 
				
			||||||
		close(e.ch)
 | 
							close(e.ch)
 | 
				
			||||||
	}
 | 
						})
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (e *namedChannelWrapper) Signaled() <-chan struct{} {
 | 
					func (e *namedChannelWrapper) Signaled() <-chan struct{} {
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user