Skip to content

Commit 1455812

Browse files
committed
Merge branch 'v3' into v3-viam
2 parents d45f63c + 540af5b commit 1455812

File tree

2 files changed

+16
-8
lines changed

2 files changed

+16
-8
lines changed

errors.go

+1
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,7 @@ var (
240240
errInvalidICEServer = errors.New("invalid ICEServer")
241241

242242
errICETransportNotInNew = errors.New("ICETransport can only be called in ICETransportStateNew")
243+
errICETransportClosed = errors.New("ICETransport closed")
243244

244245
errCertificatePEMFormatError = errors.New("bad Certificate PEM format")
245246

icetransport.go

+15-8
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,10 @@ func (t *ICETransport) Start(gatherer *ICEGatherer, params ICEParameters, role *
157157
return err
158158
}
159159

160+
if t.State() == ICETransportStateClosed {
161+
return errICETransportClosed
162+
}
163+
160164
t.conn = iceConn
161165

162166
config := mux.Config{
@@ -200,28 +204,31 @@ func (t *ICETransport) GracefulStop() error {
200204

201205
func (t *ICETransport) stop(shouldGracefullyClose bool) error {
202206
t.lock.Lock()
203-
defer t.lock.Unlock()
204-
205207
t.setState(ICETransportStateClosed)
206208

207209
if t.ctxCancel != nil {
208210
t.ctxCancel()
209211
}
210212

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+
211218
if t.mux != nil {
212219
var closeErrs []error
213-
if shouldGracefullyClose && t.gatherer != nil {
220+
if shouldGracefullyClose && gatherer != nil {
214221
// we can't access icegatherer/icetransport.Close via
215222
// mux's net.Conn Close so we call it earlier here.
216-
closeErrs = append(closeErrs, t.gatherer.GracefulClose())
223+
closeErrs = append(closeErrs, gatherer.GracefulClose())
217224
}
218-
closeErrs = append(closeErrs, t.mux.Close())
225+
closeErrs = append(closeErrs, mux.Close())
219226
return util.FlattenErrs(closeErrs)
220-
} else if t.gatherer != nil {
227+
} else if gatherer != nil {
221228
if shouldGracefullyClose {
222-
return t.gatherer.GracefulClose()
229+
return gatherer.GracefulClose()
223230
}
224-
return t.gatherer.Close()
231+
return gatherer.Close()
225232
}
226233
return nil
227234
}

0 commit comments

Comments
 (0)