|  | @@ -12,6 +12,7 @@ type ActivityUpdater interface {
 | 
	
		
			
				|  |  |  type ActivityTimer struct {
 | 
	
		
			
				|  |  |  	updated chan bool
 | 
	
		
			
				|  |  |  	timeout chan time.Duration
 | 
	
		
			
				|  |  | +	closing chan bool
 | 
	
		
			
				|  |  |  }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  func (t *ActivityTimer) Update() {
 | 
	
	
		
			
				|  | @@ -22,11 +23,17 @@ func (t *ActivityTimer) Update() {
 | 
	
		
			
				|  |  |  }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  func (t *ActivityTimer) SetTimeout(timeout time.Duration) {
 | 
	
		
			
				|  |  | -	t.timeout <- timeout
 | 
	
		
			
				|  |  | +	select {
 | 
	
		
			
				|  |  | +	case <-t.closing:
 | 
	
		
			
				|  |  | +	case t.timeout <- timeout:
 | 
	
		
			
				|  |  | +	}
 | 
	
		
			
				|  |  |  }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  func (t *ActivityTimer) run(ctx context.Context, cancel context.CancelFunc) {
 | 
	
		
			
				|  |  | -	defer cancel()
 | 
	
		
			
				|  |  | +	defer func() {
 | 
	
		
			
				|  |  | +		cancel()
 | 
	
		
			
				|  |  | +		close(t.closing)
 | 
	
		
			
				|  |  | +	}()
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  	timeout := <-t.timeout
 | 
	
		
			
				|  |  |  	if timeout == 0 {
 | 
	
	
		
			
				|  | @@ -66,6 +73,7 @@ func CancelAfterInactivity(ctx context.Context, cancel context.CancelFunc, timeo
 | 
	
		
			
				|  |  |  	timer := &ActivityTimer{
 | 
	
		
			
				|  |  |  		timeout: make(chan time.Duration, 1),
 | 
	
		
			
				|  |  |  		updated: make(chan bool, 1),
 | 
	
		
			
				|  |  | +		closing: make(chan bool),
 | 
	
		
			
				|  |  |  	}
 | 
	
		
			
				|  |  |  	timer.timeout <- timeout
 | 
	
		
			
				|  |  |  	go timer.run(ctx, cancel)
 |