netstack: do not defer panicable logic in tcp main loop.

PiperOrigin-RevId: 204355026
Change-Id: I1a8229879ea3b58aa861a4eb4456fd7aff99863d
This commit is contained in:
Zhaozhong Ni
2018-07-12 13:39:28 -07:00
committed by Shentubot
parent 67507bd579
commit cc34a90fb4
+9 -5
View File
@@ -828,7 +828,7 @@ func (e *endpoint) protocolMainLoop(handshake bool) *tcpip.Error {
var closeTimer *time.Timer
var closeWaker sleep.Waker
defer func() {
epilogue := func() {
// e.mu is expected to be hold upon entering this section.
if e.snd != nil {
@@ -849,7 +849,7 @@ func (e *endpoint) protocolMainLoop(handshake bool) *tcpip.Error {
// When the protocol loop exits we should wake up our waiters.
e.waiterQueue.Notify(waiter.EventHUp | waiter.EventErr | waiter.EventIn | waiter.EventOut)
}()
}
if handshake {
// This is an active connection, so we must initiate the 3-way
@@ -867,7 +867,8 @@ func (e *endpoint) protocolMainLoop(handshake bool) *tcpip.Error {
e.mu.Lock()
e.state = stateError
e.hardError = err
// Lock released in deferred statement.
// Lock released below.
epilogue()
return err
}
@@ -1013,7 +1014,9 @@ func (e *endpoint) protocolMainLoop(handshake bool) *tcpip.Error {
if err := funcs[v].f(); err != nil {
e.mu.Lock()
e.resetConnectionLocked(err)
// Lock released in deferred statement.
// Lock released below.
epilogue()
return nil
}
}
@@ -1021,7 +1024,8 @@ func (e *endpoint) protocolMainLoop(handshake bool) *tcpip.Error {
// Mark endpoint as closed.
e.mu.Lock()
e.state = stateClosed
// Lock released in deferred statement.
// Lock released below.
epilogue()
return nil
}