@@ -157,6 +157,10 @@ func (t *ICETransport) Start(gatherer *ICEGatherer, params ICEParameters, role *
157
157
return err
158
158
}
159
159
160
+ if t .State () == ICETransportStateClosed {
161
+ return errICETransportClosed
162
+ }
163
+
160
164
t .conn = iceConn
161
165
162
166
config := mux.Config {
@@ -200,28 +204,31 @@ func (t *ICETransport) GracefulStop() error {
200
204
201
205
func (t * ICETransport ) stop (shouldGracefullyClose bool ) error {
202
206
t .lock .Lock ()
203
- defer t .lock .Unlock ()
204
-
205
207
t .setState (ICETransportStateClosed )
206
208
207
209
if t .ctxCancel != nil {
208
210
t .ctxCancel ()
209
211
}
210
212
213
+ // mux and gatherer can only be set when ICETransport.State != Closed.
214
+ mux := t .mux
215
+ gatherer := t .gatherer
216
+ t .lock .Unlock ()
217
+
211
218
if t .mux != nil {
212
219
var closeErrs []error
213
- if shouldGracefullyClose && t . gatherer != nil {
220
+ if shouldGracefullyClose && gatherer != nil {
214
221
// we can't access icegatherer/icetransport.Close via
215
222
// mux's net.Conn Close so we call it earlier here.
216
- closeErrs = append (closeErrs , t . gatherer .GracefulClose ())
223
+ closeErrs = append (closeErrs , gatherer .GracefulClose ())
217
224
}
218
- closeErrs = append (closeErrs , t . mux .Close ())
225
+ closeErrs = append (closeErrs , mux .Close ())
219
226
return util .FlattenErrs (closeErrs )
220
- } else if t . gatherer != nil {
227
+ } else if gatherer != nil {
221
228
if shouldGracefullyClose {
222
- return t . gatherer .GracefulClose ()
229
+ return gatherer .GracefulClose ()
223
230
}
224
- return t . gatherer .Close ()
231
+ return gatherer .Close ()
225
232
}
226
233
return nil
227
234
}
0 commit comments