mirror of
https://github.com/coder/coder.git
synced 2025-07-10 23:53:15 +00:00
fix: force logs to flush on close in peer.(*Conn) (#1268)
This commit is contained in:
14
peer/conn.go
14
peer/conn.go
@ -147,6 +147,7 @@ func (c *Conn) logger() slog.Logger {
|
||||
if !valid {
|
||||
return slog.Logger{}
|
||||
}
|
||||
|
||||
return log
|
||||
}
|
||||
|
||||
@ -566,11 +567,14 @@ func (c *Conn) isClosed() bool {
|
||||
func (c *Conn) CloseWithError(err error) error {
|
||||
c.closeMutex.Lock()
|
||||
defer c.closeMutex.Unlock()
|
||||
|
||||
if c.isClosed() {
|
||||
return c.closeError
|
||||
}
|
||||
|
||||
c.logger().Debug(context.Background(), "closing conn with error", slog.Error(err))
|
||||
logger := c.logger()
|
||||
|
||||
logger.Debug(context.Background(), "closing conn with error", slog.Error(err))
|
||||
if err == nil {
|
||||
c.closeError = ErrClosed
|
||||
} else {
|
||||
@ -588,11 +592,11 @@ func (c *Conn) CloseWithError(err error) error {
|
||||
// Waiting for pion/webrtc to report closed state on both of these
|
||||
// ensures no goroutine leaks.
|
||||
if c.rtc.ConnectionState() != webrtc.PeerConnectionStateNew {
|
||||
c.logger().Debug(context.Background(), "waiting for rtc connection close...")
|
||||
logger.Debug(context.Background(), "waiting for rtc connection close...")
|
||||
<-c.closedRTC
|
||||
}
|
||||
if c.rtc.ICEConnectionState() != webrtc.ICEConnectionStateNew {
|
||||
c.logger().Debug(context.Background(), "waiting for ice connection close...")
|
||||
logger.Debug(context.Background(), "waiting for ice connection close...")
|
||||
<-c.closedICE
|
||||
}
|
||||
|
||||
@ -600,9 +604,11 @@ func (c *Conn) CloseWithError(err error) error {
|
||||
// All logging, goroutines, and async functionality is cleaned up after this.
|
||||
c.dcClosedWaitGroup.Wait()
|
||||
|
||||
c.logger().Debug(context.Background(), "closed")
|
||||
// Disable logging!
|
||||
c.loggerValue.Store(slog.Logger{})
|
||||
logger.Sync()
|
||||
|
||||
logger.Debug(context.Background(), "closed")
|
||||
close(c.closed)
|
||||
return err
|
||||
}
|
||||
|
Reference in New Issue
Block a user