File tree Expand file tree Collapse file tree 2 files changed +12
-5
lines changed Expand file tree Collapse file tree 2 files changed +12
-5
lines changed Original file line number Diff line number Diff line change @@ -135,6 +135,7 @@ func (c *Channel) init() {
135
135
136
136
c .conn .dcDisconnectListeners .Add (1 )
137
137
c .conn .dcFailedListeners .Add (1 )
138
+ c .conn .dcClosedWaitGroup .Add (1 )
138
139
go func () {
139
140
var err error
140
141
// A DataChannel can disconnect multiple times, so this needs to loop.
@@ -274,6 +275,7 @@ func (c *Channel) closeWithError(err error) error {
274
275
close (c .sendMore )
275
276
c .conn .dcDisconnectListeners .Sub (1 )
276
277
c .conn .dcFailedListeners .Sub (1 )
278
+ c .conn .dcClosedWaitGroup .Done ()
277
279
278
280
if c .rwc != nil {
279
281
_ = c .rwc .Close ()
Original file line number Diff line number Diff line change @@ -113,6 +113,7 @@ type Conn struct {
113
113
dcDisconnectListeners atomic.Uint32
114
114
dcFailedChannel chan struct {}
115
115
dcFailedListeners atomic.Uint32
116
+ dcClosedWaitGroup sync.WaitGroup
116
117
117
118
localCandidateChannel chan webrtc.ICECandidateInit
118
119
localSessionDescriptionChannel chan webrtc.SessionDescription
@@ -125,11 +126,10 @@ type Conn struct {
125
126
pingEchoChan * Channel
126
127
pingEchoOnce sync.Once
127
128
pingEchoError error
128
-
129
- pingMutex sync.Mutex
130
- pingOnce sync.Once
131
- pingChan * Channel
132
- pingError error
129
+ pingMutex sync.Mutex
130
+ pingOnce sync.Once
131
+ pingChan * Channel
132
+ pingError error
133
133
}
134
134
135
135
func (c * Conn ) init () error {
@@ -502,5 +502,10 @@ func (c *Conn) CloseWithError(err error) error {
502
502
// this call will return an error that isn't typed. We don't check the error because
503
503
// closing an already closed connection isn't an issue for us.
504
504
_ = c .rtc .Close ()
505
+
506
+ // Waits for all DataChannels' to exit before officially labeling as closed.
507
+ // All logging, goroutines, and async functionality is cleaned up after this.
508
+ c .dcClosedWaitGroup .Wait ()
509
+
505
510
return err
506
511
}
You can’t perform that action at this time.
0 commit comments