mirror of
				https://github.com/fluffle/goirc
				synced 2025-11-04 03:58:03 +00:00 
			
		
		
		
	client/connection: fix deadlock on event dispatch
This commit is contained in:
		
							parent
							
								
									0cac69d2ee
								
							
						
					
					
						commit
						1ebd4aa913
					
				
					 1 changed files with 5 additions and 1 deletions
				
			
		| 
						 | 
				
			
			@ -207,6 +207,8 @@ func (conn *Conn) DisableStateTracking() {
 | 
			
		|||
 | 
			
		||||
// Per-connection state initialisation.
 | 
			
		||||
func (conn *Conn) initialise() {
 | 
			
		||||
	conn.mu.Lock()
 | 
			
		||||
	defer conn.mu.Unlock()
 | 
			
		||||
	conn.io = nil
 | 
			
		||||
	conn.sock = nil
 | 
			
		||||
	conn.die = make(chan struct{})
 | 
			
		||||
| 
						 | 
				
			
			@ -404,8 +406,8 @@ func (conn *Conn) shutdown() {
 | 
			
		|||
	// Guard against double-call of shutdown() if we get an error in send()
 | 
			
		||||
	// as calling sock.Close() will cause recv() to receive EOF in readstring()
 | 
			
		||||
	conn.mu.Lock()
 | 
			
		||||
	defer conn.mu.Unlock()
 | 
			
		||||
	if !conn.connected {
 | 
			
		||||
		conn.mu.Unlock()
 | 
			
		||||
		return
 | 
			
		||||
	}
 | 
			
		||||
	logging.Info("irc.shutdown(): Disconnected from server.")
 | 
			
		||||
| 
						 | 
				
			
			@ -415,6 +417,8 @@ func (conn *Conn) shutdown() {
 | 
			
		|||
	conn.wg.Wait()
 | 
			
		||||
	// Dispatch after closing connection but before reinit
 | 
			
		||||
	// so event handlers can still access state information.
 | 
			
		||||
	// Release lock before dispatch or we block handlers from accessing Me()
 | 
			
		||||
	conn.mu.Unlock()
 | 
			
		||||
	conn.dispatch(&Line{Cmd: DISCONNECTED, Time: time.Now()})
 | 
			
		||||
	// reinit datastructures ready for next connection
 | 
			
		||||
	conn.initialise()
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue